Question 15.4: varargs/varargs1.html
In the example code there, they seem to think va_arg returns NULL if the end of the list has been reached:
len = strlen(first);
va_start(argp, first);
while((p = va_arg(argp, char *)) != NULL)
len += strlen(p);
va_end(argp);
But the documentation for va_arg explicitly says this is not the case, and that va_arg will happily go past the end of the list.
This agrees with my experience trying to imitate the above code and getting a segfault as a result.
Indeed,
va_argdoesn’t mention returningNULLat the nd of the list.But the FAQ says:
Which means they assume the caller will pass
NULLas the last argument to signal the end of the list.