3 ms·
No need to define offsetof, it’s part of <stddef.h> Still interesting to see the trick behind it tho.
by srgpqt 6y ago
No need to define offsetof, it’s part of <stddef.h>
Still interesting to see the trick behind it tho.
- annilt 6y agoIt’s added to the standard because macro version has undefined behavior. (yet it still works on any compiler without a problem)
- londons_explore 6y agoI was about to ask if it was legal to dereference a null pointer and then take the address of it... I presume it is not, but I'm surprised compilers don't complain at compilation time.
- saagarjha 6y agoDereferencing a null pointer and then immediately "undoing" it by taking its address is actually legal, I believe. I think the undefined behavior here is the member access instead of the magic sequence &* which is supposed to cancel out.