Skip to content

Instantly share code, notes, and snippets.

@irondoge
Created July 8, 2016 19:01
Show Gist options
  • Select an option

  • Save irondoge/f4e6f8d5c35c6a8b7196068182c0d9d5 to your computer and use it in GitHub Desktop.

Select an option

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]
#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