如何使用C ++(g ++)编译器编译包含C ++关键字的C代码?

How does one compile C code, containing C++ keywords, using a C++(g++) compiler?

有没有办法使用C++(g++)编译器编译这样的C代码。

例如,是否可以编译和运行以下代码:

1
2
3
4
5
6
int main()
{
    int private;
    private = 9;
    return private;
}

它具有EDCOX1×0变量名,这是一个C++关键字。

真正的项目是,与C和C++代码混合,驱动程序是用C编写的,有些结构有EDCOX1的成员名称,比如0,但是应用程序是用C++编写的,我已经尝试使用SUSTN"C",但是不起作用。


您可以将g++与选项-x c一起使用,或者使用gcc。

实况示例可以使用"-x"选项显式指定输入语言:

-x language
Specify explicitly the language for the following input files (rather than letting the compiler choose a default based on the file
name suffix). This option applies to all following input files until
the next `-x' option. Possible values for language are:

1
2
3
4
5
6
c  c-header  cpp-output
c++  c++-cpp-output
objective-c  objc-cpp-output
assembler  assembler-with-cpp
f77  f77-cpp-input  ratfor
java

-x none
Turn off any specification of a language, so that subsequent files are handled according to their file name suffixes (as they are if `-x'
has not been used at all).

从这里引述