Code: Select all
403 #define NULL __null
404 #else /* G++ */
405 #ifndef __cplusplus
406 #define NULL ((void *)0)
407 #else /* C++ */
408 #define NULL 0
Code: Select all
403 #define NULL __null
404 #else /* G++ */
405 #ifndef __cplusplus
406 #define NULL ((void *)0)
407 #else /* C++ */
408 #define NULL 0
How is the appropriate definition for a given context chosen?
void* is a type. The type of a pointer with its type cast away to be more specific. You have probably seen char* or int*. These are pointers to characters or integers respectively. In some instances, it is useful to cast away the specific type or return an address to memory without a type. For example, malloc returns a chunk of bytes (void*) and you give it the type (e.g., int* p = malloc(sizeof(int) * 1024)).And what exactly does ((void *) 0) mean?
Nothing. Seriously, it is a memory address that is never allocated, so it represents a pointer to nowhere. It is similar to the null terminator of a string.My book says that it is simply an address, but what does the 0 represent?