Ayrat
Ayrat

Reputation: 1259

How to pass -std=c99 to g++?

My cpp file includes C header that has a enumerator with comma at the end. As a result g++ produces warning:

warning: comma at end of enumerator list

How can I tell g++ to use -std=c99 for that cpp file? That is, how can I avoid this warning?

I already tried: -std=c99 but it resulted in: "cc1plus: warning: command line option "-std=c99" is valid for C/ObjC but not for C++"

Note: the inclusion of C headers is surrounded with extern "C" command.

Upvotes: 1

Views: 5300

Answers (2)

Keith Thompson
Keith Thompson

Reputation: 263177

You don't. g++ compiles C++, not C. A C header included in a C++ source file still has to follow C++ rules, even with extern "C". For example, the header cannot use class as an identifier.

Upvotes: 3

LaC
LaC

Reputation: 12824

#include works by simply inserting the text of the included file in the position where the #include line occurs. The result of preprocessing is a single text file which is then sent to the compiler, and you cannot change the language in the middle of the file.

Since your cpp file is being compiled as C++ code, the headers it includes will be as well. extern "C" does not change the language; it simply tells the C++ compiler that the functions declared within use the C calling convention.

Upvotes: 2

Related Questions