5 ms·
The problem is that (correct me if I'm wrong) an expression like "&foo->bar" counts as a dereference of foo, even though the result of the expression is simple
by rav 12y ago
The problem is that (correct me if I'm wrong) an expression like "&foo->bar" counts as a dereference of foo, even though the result of the expression is simple pointer arithmetic involving foo (adding the offset of the bar member).
- pcwalton 12y agoYes, you're correct [1], and that's why offsetof is a builtin in gcc and clang. Even more insidious is the fact that memcpy of zero bytes from or to null is undefined behavior. [1]: http://stackoverflow.com/questions/26906621/does-struct-name-null-b-cause-undefined-behaviour-in-c11 http://stackoverflow.com/questions/26906621/does-struct-name...
- haberman 12y agoThat's what offsetof() is for! http://man7.org/linux/man-pages/man3/offsetof.3.html http://man7.org/linux/man-pages/man3/offsetof.3.html