Re:I Do Not Know C: Short quiz on undefined behavior (2015)
by DSMan195276 on Monday February 13, 2017 @09:48PM
(#13640773)
You're thinking about it in the context of actual computers. The C standard says absolutely nothing about what NULL has to be, besides that the integer value 0 is considered to be the NULL address and that dereferencing it is considered invalid. The NULL address does not have to be all 0 bits. Architectures are generally free to define it to any invalid address they want to be NULL, 0 just happens to be a common and easy one. The catch you're pointing out is that on x86 there are technically no 'invalid' addresses, so we just use 0 and assume you won't ever attempt to use the stuff there (Which in practice on x86, nobody puts anything there).
[ Parent
| on HN ]
Re:I Do Not Know C: Short quiz on undefined behavior (2015)
by sjolsen on Monday February 13, 2017 @11:10PM
(#13641067)
>The catch you're pointing out is that on x86 there are technically no 'invalid' addresses
Depending on what you mean precisely by "x86," there is such a thing as an invalid address: the IA32e architecture (or whatever you want to call Intel's flavour of 64-bit "x86") requires that the <n> high bits of an address match, where <n> is machine-dependent.
Re:I Do Not Know C: Short quiz on undefined behavior (2015)
by DSMan195276 on Tuesday February 14, 2017 @01:15AM
(#13641594)
That's a fair point - though I think you could debate whether or not the current 48-bit address space of x86-64 is part of the architecture or just an implementation detail. But in the end I don't really think it matters which you consider it (And I'd be happy to consider it to be either). All that said, you're completely right that with current x86-64, there are 64-bit values that could never be a valid address.