CCASTING THE NULL POINTER
Consider the following call to the variadic function execl():
execl("ls", "ls", "-l", (char *) NULL);
A variadic function is one that takes a variable number of arguments or arguments of varying types.
Whether the cast is required before the NULL in cases like this is the source of some confusion. While we can often get away without the cast, the C standards require it; failure to include it may lead an application to break on some systems.
NULL is typically defined as either 0 or as (void *) 0. (The C standards allow other definitions, but they are essentially equivalent to one of these two possibilities.) The main reason casts are needed is that NULL is allowed to be defined as 0, so this is the case we examine first. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access