I\'m writing C code for a system where address 0x0000 is valid and contains port I/O. Therefore, any possible bugs that access a NULL pointer will remain undetected and at t
Considering the extreme difficulty in redefining NULL as mentioned by others, maybe its easier to redefine dereferencing for well-known hardware addresses. When creating an address, add 1 to every well-known address, so that your well-known IO port would be:
#define CREATE_HW_ADDR(x)(x+1)
#define DEREFERENCE_HW_ADDR(x)(*(x-1))
int* wellKnownIoPort = CREATE_HW_ADDR(0x00000000);
printf("IoPortIs" DEREFERENCE_HW_ADDR(wellKnownIoPort));
If the addresses you're concerned with are grouped together and you can feel safe that adding 1 to the address won't conflict with anything (which it shouldn't in most cases), you might be able to do this safely. And then you don't need to worry about rebuilding your tool chain/std lib and expressions in the form:
if (pointer)
{
...
}
still work
Crazy I know, but just thought I'd throw the idea out there :).