Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC: Is it possible to disable the "comma at end of enumerator list" warning when using -pedantic?

Tags:

enums

gcc

I'm compiling C++ code and I'd like to enable the -pedantic option.
I'm using GCC 4.0, running Xcode on Mac OS X Leopard.
It is for example possible to allow variadic macros and the long long type that are normally forbidden when using -pedantic (with -Wno-variadic-macros and -Wno-long-long). But I could not find anything to disable the "comma at end of enumerator list" warning.
Is it possible?

Thanks.

like image 909
Guillaume Avatar asked Jun 16 '09 16:06

Guillaume


2 Answers

A comma at the end of an enumerator is valid in C99 but not in C89, so the following will work providing your code is valid C99

gcc -std=c99 -pedantic foo.c

I'm fairly sure that it's not valid in C++ (according to g++) at all

Edit: tested this with GCC 4.2.1 on HP-UX and it works with no errors / warnings foo.c

int main(int argc, char** argv) {
    enum { A, B, };
    return 0;
}


gcc -std=c99 -pedantic foo.c
like image 138
Glen Avatar answered Nov 19 '22 05:11

Glen


In C++ it is not yet possible to disable it, even though it legal in C++11. So in the future, when GCC is corrected, -std=c++11 should disable it.

-std=c99 only works in C, not C++ (as in the question).

like image 2
StellarVortex Avatar answered Nov 19 '22 03:11

StellarVortex