/* Compile with gcc -shared -o testcase.so testcase.c */ #include #include #include struct Foo { int aNumber; struct Bar *bar; }; struct Bar { char const *aString; int anotherNumber; }; struct Foo *make_foo(int aNumber, char const *aString, int anotherNumber) { struct Foo *foo = malloc(sizeof(struct Foo)); printf("malloced foo = %p\n", foo); foo->aNumber = aNumber; foo->bar = malloc(sizeof(struct Bar)); printf("malloced bar = %p\n", foo->bar); foo->bar->aString = strdup(aString); foo->bar->anotherNumber = anotherNumber; return foo; }