views:

207

answers:

3
+7  Q: 

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.

+15  A: 

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
codaddict
+3  A: 

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

Rohit
A: 

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.

ldav1s