The C implementation of myFunc
has a bug: info
is a pointer and you assign a stack pointer to it and return it from the function. But that pointer becomes invalid when leaving the scope of myFunc
. It might still work in some cases, like the printf
expression shows, but that’s just lucky.
You’ll be able to observe the same behaviour calling myFunc
from C.
To fix this, you could allocate *s
on the heap, just like *d
.