4 ms·
to be pedantic the pointer is not being dereferenced (the '&' inhibits that part of the operation)
by Taniwha 12y ago
to be pedantic the pointer is not being dereferenced (the '&' inhibits that part of the operation)
- _kst_ 12y agoStrictly 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.