I am trying to write a function which takes variadic parameters. It has the following prototype:
void foo(const char *name, const char *file, uint32_t line, const char *fmt, ...);
and I call it with the following macro:
#define FOO(name, ...) \
foo(name, __FILE__, __LINE__, __VA_ARGS__);
From what I understand the following will be valid:
FOO("Example, "Hello %s", "Stack Overflow");
But will the following result in undefined behavior in a standards compliant c99 compiler?
FOO("Example", "Hello Stack Overflow");
My worry is that because the foo
is expecting both *fmt
as well as ...
that a trailing ,
will be added when there are only two arguments passed to the macro.
Can anyone tell me if the above is valid c99?
EDIT: When I run this with gcc and std=c99
it works, but I am worried that there is silent UB
Thank you!