C++ preprocessor
I'd rewritten a simple C++ program using unix
as a variable name. 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
.
I want to know list of all such predefined macros.
You can list all the predefined macros by using the GNU preprocessor cpp
as:
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:
g++ -ansi file.cpp
And you can use the -ansi
flag with cpp
also to get the list of all standard predefined macros:
cpp -dM -ansi file.cpp
touch mysymdef.h; g++ -dM mysymdef.h It will generate a file mysymdef.h.gch which will have all predefined symbols/macros for you system. 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/System_002dspecific-Predefined-Macros.html
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.
$ uname
Linux
$ cpp -dM <<<'' | grep unix
#define __unix__ 1
#define __unix 1
#define unix 1
精彩评论