Does the 'offsetof' macro from <stddef.h> invoke undefined behaviour?
Example from MSVC's implementation: #define offsetof(s,m) \ (size_t)&reinterpret_cast<const volatile char&>((((s *)0)->m)) // ^^^^^^^^^^^ As can be seen, it dereferences a null pointer, which normally invokes undefined behaviour. Is this an exception to the rule or what is going on? Where the language standard says "undefined behavior", any given compiler can define the behavior. Implementation code in the standard library typically relies on that. So there are two questions: (1) Is the code UB with respect to the C++ standard? That's a really hard question, because it's a well known almost