Multiple choice

int debug (const char * fmt, ...) { extern FILE * logfile; va_list args; assert(fmt); args = va_arg(fmt, va_list); return vfprintf(logfile, fmt, args); } The function debug(), defined above, contains an error. Which one of the following describes it?

  1. The ellipsis is a throwback from K&R C. In accordance with Standard C, the declaration of args should be moved into the parameter list, and the K&R C macro va_arg() should be deleted from the code.

  2. vfprintf() does not conform to ISO 9899: 1990, and may not be portable.

  3. Library routines that accept argument lists cause a fault on receipt of an empty list. The argument list must be validated with va_null() before invoking vfprintf().

  4. The argument list args has been improperly initialized.

  5. Variadic functions are discontinued by Standard C; they are legacy constructs from K&R C, and no longer compile under modern compilers.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In the provided function, args is initialized using va_arg(fmt, va_list), which is incorrect because va_arg requires a type and advances the list, whereas va_start should be used to initialize a va_list from a parameter.