Re:WebAssembly doesn’t make unsafe languages safe
by sigjuice on Sunday November 25, 2018 @07:14PM
(#18529970)
What part of the C standard allows for the NULL pointer to be numerically any value? I am looking at n1256.pdf, but I can't seem to find the relevant text.
[ Parent
| on HN ]
Re:WebAssembly doesn’t make unsafe languages safe
by int_19h on Sunday November 25, 2018 @07:43PM
(#18530103)
It's not spelled out explicitly. Rather, what's missing from the standard is the requirement that a null pointer is all-bits-zero, or that reinterpret_cast'ing it to an integer type produces a zero (note that even these two are actually separate). This is deliberate - there have been platforms in the past where null pointer had a non-zero bit pattern for largely the same reasons (null address was valid and useful).
Re:WebAssembly doesn’t make unsafe languages safe
by sigjuice on Sunday November 25, 2018 @08:19PM
(#18530286)
n1256.pdf, Section 6.3.2.3 Pointers, says "constant expression with the value 0".
An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.
I don't think this definition excludes platforms that use non-zero bit patterns. A constant 0 in C code should get converted to the appropriate (possibly non-zero) bit-pattern for the platform.Also, my understanding is that whether the platform has useful things at address 0 falls in the category of "implementation defined".
Re:WebAssembly doesn’t make unsafe languages safe
by int_19h on Sunday November 25, 2018 @11:06PM
(#18530986)
> Also, my understanding is that whether the platform has useful things at address 0 falls in the category of "implementation defined".
If address zero is a null pointer, then IIRC no allocated object, whether static, automatic or heap, can have that address - i.e pointers to them must always compare unequal to nullptr.
If null pointer is something other than address zero, then it's just a regular address, and can have anything - it's not even "implementation defined", not anymore so than saying that e.g. 0x12345678 is a valid object address on x86.