The expresssion (void *)0
is called a null pointer.
But how about the following:
int i = 0;
void *s = (void *)i;
Is s
also a null-pointer? The C-language standard says:
6.3.2.3 Pointers
3 An integer constant expression with the value 0, such an expression cast to type void *, or the predefined constant nullptr is called a null pointer constant70). If a null pointer constant or a value of the type nullptr_t (which is necessarily the value nullptr) is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.
4 Conversion of a null pointer to another pointer type yields a null pointer of that type. Any two null pointers shall compare equal.
5 An integer may be converted to any pointer type. Except as previously specified, the result is implementation-defined, might not be correctly aligned, might not point to an entity of the referenced type, and might produce an indeterminate representation when stored into an object.71)
According to this s
would not be a null pointer?
NULL
, except for generic pointers in principle. But to my knowledge, Keil did not take the opportunity. – Hanse#define REGNAME (*(volatile uint8_t*)0)
and that's used to access a register, not as a null pointer. – Kinematograph