We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Is it safe to cast a null to struct just to get the size:
Example:
sizeof(((MEMORY_STRUCT*)0)->GWCD.sid)
Thanks JD
It depends on the compiler.
This is closely related to the offsetof() macro: en.wikipedia.org/.../Offsetof
Maybe you can do your trick using offsetof()?
says,
"The sizeof operator yields the size (in bytes) of its operand, which may be an expression ... The size is determined from the type of the operand, which is not itself evaluated" (my emphasis).
Which sounds like you should be safe?
Presumably you were worried about the NULL pointer? I don't think that should be a problem - as the expression is not evaluated...?
Crystal clear...
Thank you. JD