2 ms·
i think the issue is more that in embedded code you can't depend on the hardware to detect an access to any given memory location (the standard does permit the
by kragen 2y ago
i think the issue is more that in embedded code you can't depend on the hardware to detect an access to any given memory location (the standard does permit the bit pattern of a null pointer to be different from all zeroes, which is what you are supposed to do if you want memory location 0 to be referenceable with a pointer)
- AlotOfReading 2y agoNo compiler I'm aware of implements non-zero null pointers on systems where address 0 is valid (e.g. armv7), so it ends up being kind of a moot point.
- kragen 2y agoyeah, i'm not aware of any instances of it!
- bitwize 2y agoAs I recall the standard also mandates that ((void *)0) is a null pointer, even if it gets converted behind the scenes to some other bit pattern that represents null for that architecture. So it's all a wash.
- kragen 2y agothe standard does mandate that, yes. as i understand it, you could, for example, take the bitwise not of a pointer value to be its intptr_t value, and then use the all-ones bit pattern for your null pointer. probably a lot of existing c programs would fail to work on such an implementation (because they assume that memset with 0 will create null pointers, for example), but permitting such things was an intentional feature of the standard usually there is some memory address that you can sacrifice for null pointers