October 2004
Intermediate to advanced
624 pages
16h 2m
English
In the C programming language, the macro NULL, located in stddef.h, is used to represent a null pointer. By using this specific symbol to denote a null pointer, its meaning is obvious to the reader. Furthermore, because it is defined to be of type void*, it can help to avoid potential problems. Consider the following C API for generating and managing some kind of identified tokens:
struct Token *lookup(char const *tokenId);
void fn()
{
struct Token *token = lookup(NULL);
/* use token here */
}
lookup() will return a matching existing token, or will create a new one if tokenId is the null pointer. Because the tokenId parameter is of type char const* (to which void* is convertible in C), the author ...
Read now
Unlock full access