Skip to content

Instantly share code, notes, and snippets.

@mdippery
Created October 2, 2010 16:23
Show Gist options
  • Save mdippery/607770 to your computer and use it in GitHub Desktop.
Save mdippery/607770 to your computer and use it in GitHub Desktop.
#include <stdio.h>
struct base {
int foo;
};
struct derived {
int foo;
char *bar;
};
void foobar(void *ptr)
{
((struct base *) ptr)->foo = 100;
}
int main(int argc, char **argv)
{
struct derived d = {1, "derived"};
printf("before: %d\n", d.foo);
foobar(&d);
printf("after: %d\n", d.foo);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment