I am sorry that I cannot support my question with some code (I didnt understand how to structure it so it would be accepted here), but I try anyway.
If I understand correctly, a struct that references a struct of same type would need to do this with contained pointer for reference. Can this pointer reference to allocated space on the stack (instead of the heap) without creating segmentation fault? –
how should this be declared?
Yes, you can use pointers to variables on the stack, but only when the method that provides that stack frame has not returned. For example this will work:
This will cause an error however, as the stack frame would have disappeared:
EDIT: Well I say it will cause an error, but while calling that code with:
I get a warning during compilation:
and the program appears to work fine:
But it is, in fact, broken.