Default Compiler Defines
A quick reference for displaying default preprocessor macros across different C and C++ compilers.
The Problem
When developing cross-platform applications or debugging compiler-specific issues, it’s often useful to know what preprocessor macros are defined by default for your compiler.
Compiler Commands
Here are the command-line instructions for displaying default preprocessor macros for various C and C++ compilers:
Clang/LLVM
# For C
clang -dM -E -x c /dev/null
# For C++
clang++ -dM -E -x c++ /dev/null
GNU GCC/G++
# For C
gcc -dM -E -x c /dev/null
# For C++
g++ -dM -E -x c++ /dev/null
Other Compilers
The same pattern works for other compilers:
- Hewlett-Packard C/aC++: Use
ccoraCCwith the same flags - IBM XL C/C++: Use
xlcorxlCwith the same flags - Intel ICC/ICPC: Use
iccoricpcwith the same flags - Oracle Solaris Studio: Use
ccorCCwith the same flags - Portland Group PGCC/PGCPP: Use
pgccorpgcppwith the same flags
Command Explanation
The flags used in these commands are:
-dM: Dump preprocessor macros (instead of normal output)-E: Stop after preprocessing (don’t compile)-x: Specify the language type explicitly
Use Cases
This technique is particularly useful for:
- Cross-platform development and compatibility checks
- Understanding compiler-specific definitions
- Debugging preprocessor-related issues
- Writing portable code that adapts to different compilers
These commands provide a quick way to discover predefined macros that can be essential for writing robust, portable C and C++ code.