Skip to content
Create a gist now

Instantly share code, notes, and snippets.

#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
Something went wrong with that request. Please try again.