I was wondering:
If I have structure definitions, for example, like this:
struct Base {
int foo;
};
struct Derived {
int foo; // int foo is common for both definitions
char *bar;
};
can I do something like this?
void foobar(void *ptr) {
((struct Base *)ptr)->foo = 1;
}
struct Derived s;
foobar(&s);
e. g. cast the void pointer to Base *
to access its foo
when its type is actually Derived *
?