Quote:
Originally posted by filler_bunny
I'm having some issues with structs.
If I have a couple of nested structs, is it possible to obtain the address of a member struct, or is this something that is not good practise. I.e. is it possible to obtain the address of fooStruct->barStruct->num ?.
Sure; you can take the address of anything that lives in memory.
Quote:
Also, if I do not allocate memory for barStruct member in both of the "fooStruct" and "blahStruct" then the "num" member seems to point at exactly the same location. I.e. updating one with a value changes the other. Why is this?
At a guess? Coincidence. Dereferencing a pointer to unallocated memory is undefined; for the results you see, it's likely that, under the test conditions you had, the initial value for fooStruct->barStruct and blahStruct->barStruct was the same -- that is, they point at the same (uninitialized) place in memory.