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.
The C preprocessor is a macro processor that is used automatically by the C compiler to transform your program before actual compilation. It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs.
Preprocessing directives are lines in your program that start with # . The # is followed by an identifier that is the directive name. For example, #define is the directive that defines a macro. Whitespace is also allowed before and after the # .
There are 4 Main Types of Preprocessor Directives:Macros. File Inclusion. Conditional Compilation. Other directives.
In computer science, a preprocessor (or precompiler) is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With