[英]C++ preprocessor
I'd rewritten a simple C++ program using unix
as a variable name. 我用
unix
作为变量名重写了一个简单的C ++程序。 But the program compilation failed. 但程序编译失败了。
#include <iostream>
int main() {
int unix = 1;
return 0;
}
After searching a lot on the internet I got to this website which helped me by saying that unix
is predefined macro equal to 1
. 在网上搜索了很多之后我到了这个网站,它帮助我说
unix
是预定义的宏等于1
。
I want to know list of all such predefined macros. 我想知道所有这些预定义宏的列表。
You can list all the predefined macros by using the GNU preprocessor cpp
as: 您可以使用GNU预处理器
cpp
列出所有预定义的宏:
cpp -dM file.cpp
Also note that macros such as unix
, linux
are non standard and you can disable them by using the -ansi
compilation flag as: 另请注意,
unix
, linux
等宏是非标准的,您可以使用-ansi
编译标志禁用它们:
g++ -ansi file.cpp
And you can use the -ansi
flag with cpp
also to get the list of all standard predefined macros: 您也可以使用带有
cpp
的-ansi
标志来获取所有标准预定义宏的列表:
cpp -dM -ansi file.cpp
touch mysymdef.h; 触摸mysymdef.h; g++ -dM mysymdef.h It will generate a file mysymdef.h.gch which will have all predefined symbols/macros for you system.
g ++ -dM mysymdef.h它将生成一个文件mysymdef.h.gch,它将为您的系统提供所有预定义的符号/宏。 File is binary but with some edit it will work out.
文件是二进制的,但有一些编辑它会工作。
for details refer to 详情请参阅
http://gcc.gnu.org/onlinedocs/cpp/Invocation.html#Invocation http://gcc.gnu.org/onlinedocs/cpp/Invocation.html#Invocation
http://gcc.gnu.org/onlinedocs/cpp/System_002dspecific-Predefined-Macros.html http://gcc.gnu.org/onlinedocs/cpp/System_002dspecific-Predefined-Macros.html
$ uname
Linux
$ cpp -dM <<<'' | grep unix
#define __unix__ 1
#define __unix 1
#define unix 1
I don't think there's such a list as you are asking for that's available across every potential platform. 我不认为有这样一个列表,因为您要求的是每个潜在平台都可以使用的列表。 You may want to see Pre-defined macros for more information.
您可能希望查看预定义的宏以获取更多信息。 The 'gcc -dM' will work on Linux.
'gcc -dM'可以在Linux上运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.