Alex Rivera | Logout

C++ preprocessor

Asked 2010-10-18T10:03:31.557
11

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.

Edit
Report

1 Answer

24

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
answered 2010-10-18T10:05:59.077

Your Answer