News for hackers. Stuff that matters.
Re:Null Pointer Dereferencing Causes Undefined Behavior by Taniwha on Monday April 20, 2015 @07:34PM (#9411468)
to be pedantic the pointer is not being dereferenced (the '&' inhibits that part of the operation)
Re:Null Pointer Dereferencing Causes Undefined Behavior by _kst_ on Tuesday April 21, 2015 @04:34PM (#9416883)
Strictly speaking, yes, it is, at least in the abstract machine.

If a unary "&" is applied directly to the result of a unary "" operator, then neither is evaluated. But in this case, the "&" is being applied to "((st )0)->m". "x->y" is syntactic sugar for "(x).y", so this is equivalent to If a unary "&" is applied directly to the result of a unary "" operator, then neither is evaluated. But in this case, the "&" is being applied to "((st )0)->m". "x->y" is syntactic sugar for "(x).y", so this is equivalent to "((st )0)).m)".

A compiler will very likely optimize the expression so it doesn't generate machine code to dereference the null pointer. And in fact using this definition for the offsetof macro depends on that optimization, and on the compiler treating a null pointer as address 0.