Created
July 8, 2016 19:01
-
-
Save irondoge/f4e6f8d5c35c6a8b7196068182c0d9d5 to your computer and use it in GitHub Desktop.
acces parent-struct fields from a child-struct [compilation: gcc -W -Wall -Wextra -std=c89 -fms-extensions polymorphism.c]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| struct poly_parent | |
| { | |
| int a; | |
| char b; | |
| void *c; | |
| }; | |
| struct poly_child | |
| { | |
| struct poly_parent; | |
| short d; | |
| }; | |
| int main() | |
| { | |
| struct poly_child test; | |
| test.a = 42; | |
| test.d = 21; | |
| printf("%d %d\n", test.a, test.d); | |
| return (0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment