mercredi 31 août 2016

Is offsetof dereferencing a null pointer [duplicate]

This question already has an answer here:

In looking at how my compiler (VS2015) implements the offsetof macro, I see the following implementation:

#define offsetof(s,m) ((size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m)))

It appears to me that this is dereferencing a null pointer at ((s*)0)->m. I understand this to be undefined behavior. Is this undefined behavior that the compiler specifies more strongly than the language, or is there some nuance to the "never dereference a null pointer" rule that I don't understand?

Aucun commentaire:

Enregistrer un commentaire