I have a simple: #define log(text, ...) fprintf(stderr, "stuff before" text "stuff after", ## __VA_ARGS__);
which is triggering: error: ISO C99 requires at least one argument for the "..." in a variadic macro [-Werror]
Should using -std=c11
and -Wno-variadic-macros
not fix this error / warning?
Throwing #pragma GCC system_header
in the header file before the define of log fixes this issue (haven't necessarily tested if the outputted binary works...) but this seems sort of hacky and I'm not entirely sure the ramifications of this.
Here's an example of expected behaviour: https://stackoverflow.com/a/31327708/5698848
-Wvariadic-macros
Warn if variadic macros are used in ISO C90 mode, or if the GNU alternate syntax is used in ISO C99 mode.
This is enabled by either -Wpedantic or -Wtraditional.
To inhibit the warning messages, use -Wno-variadic-macros.
Any idea on an elegant solution to stop this warning / error from legal GNU GCC C code? Why does it say I'm using C99 and why doesn't the flag to disable the warning for C99 work? Line looks like:
gcc -c src/file.c -Wall -Werror -Wextra -pedantic -Wfloat-equal -Wwrite-strings -Wcast-qual -Wunreachable-code -Wcast-align -Wstrict-prototypes -Wundef -Wshadow -Wstrict-aliasing -Wstrict-overflow -Wno-variadic-macros -g3 -std=c11 -O2 -flto -Iinclude/ -MMD -MF depend/file.d -o bin/file.o
Note that -pedantic
is indeed the culprit.
MCVE
c.c
#include <stdio.h>
#include <stdlib.h>
#define log(text, ...) fprintf(stderr, "stuff before" text "stuff after", ## __VA_ARGS__);
int main(void)
{
log("should work, but doesn't");
log("works fine: %s", "yep");
return EXIT_SUCCESS;
}
Makefile
all:
gcc c.c -Wall -Werror -Wextra -pedantic -Wfloat-equal -Wwrite-strings -Wcast-qual -Wunreachable-code -Wcast-align -Wstrict-prototypes -Wundef -Wshadow -Wstrict-aliasing -Wstrict-overflow -Wno-variadic-macros -g3 -std=c11 -O2
Note: Removing pedantic compiles fine - gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609