I noticed some potential problem with a macro va_argthat is used to get an unnamed parameter from a function variable. Consider the following simplified example:
#include <stdio.h>
#include <stdarg.h>
void foo(int n, ...)
{
va_list ap;
const char *s;
va_start(ap, n);
for (s = va_arg(ap, const char *); *s != '\0'; s++)
putchar(*s);
va_end(ap);
}
int main(void)
{
char str[] = "xyz";
foo(1, str);
return 0;
}
The link to va_argindicates that (my selection):
If va_arg is called when there are no more arguments in ap, or if the type of the next argument in ap (after promotions) is incompatible with T, the behavior is undefined (...)
, const char * char * . char foo, char ( ), , const- :
s = va_arg(ap, const char *)
"" UB. , arr const, char *, , . int * const int *.