Comment by saagarjha
3 years ago
There’s a lot of platforms where you might want to do this. If you’re programming baremetal the “address 0” might be a physical address that you expect stuff to exist at, so it might be relevant to use the bit pattern 0xffffffff instead. If you’re targeting a blockchain or WASM VM you may not also not have memory protection to work with, just a linear array of memory. And some machines don’t even have bit patterns for pointers, like say a Lisp machine.
There are many MCUs where flash is mapped to 0x0 but NULL is still 0.
It’s not really a problem in practice unless you want to dump the whole flash and some != NULL check somewhere
For an older CPU example, x86 (in 16 bit mode) maps the interrupt table at the physical address 0. So to tell the CPU what handler to use for the 0th interrupt, you have to do:
Granted, most 16 bit OSs were written in assembly, not C, but if you were to write one in C, you’d have this problem.
IIRC, the M68k (which was a popular C target with official Linux support) did the same thing.
For a more recent example, AVR (popularized by Arduino) maps it’s registers into RAM starting at address 0. So, if you wanted to write to r0, you could write to NULL instead. Although one would be using assembly for this, not C.