Reputation: 123
Here is source code:
#include <stdarg.h>
void foo(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int a, b, d, e;
double c;
a = va_arg(ap, int);
va_end(ap);
}
And here is the code after preprocessing(ignoring #include and preprocessor comments(#)):
void foo(char *fmt, ...)
{
va_list ap;
__builtin_va_start(ap, fmt);
int a, b, d, e;
double c;
a = __builtin_va_arg(ap, int); // int as an argument after processing!
__builtin_va_end(ap);
}
so, how does __builtin_va_arg(ap, int) works ? When this macro expanded ?
Upvotes: 1
Views: 3310
Reputation: 241691
These are not macros. They are built-in primitives implemented by the compiler itself. (That is, the particular compiler you are using.)
The actual syntax and semantics of these built-ins is deliberately not documented. You must not use them directly in a program, as indicated by the fact that their names start with two underscores. (Only documented symbols starting with two underscores may be used in a program.) When the compiler encounters them after preprocessing, it will emit the appropriate code (which likely cannot be written in C).
Upvotes: 3