Choosing the C Standard in g Compilations
Compiling C code with g requires consideration of the C standard version to avoid potential errors. By default, g uses a specific standard version, but it can be overridden using command-line arguments.
Default Standard Version
The default standard version used by g can be determined by executing the command:
g++ -dM -E -x c++ /dev/null | grep -F __cplusplus
This command outputs a macro that defines the __cplusplus preprocessor macro, indicating the version of the C standard being used. For example:
#define __cplusplus 199711L // Represents C++98
Overriding the Default Version
To override the default standard version, use the -std= argument followed by the desired version. For instance, to use C 17, the command would be:
g++ -std=c++17 example.cpp
Recommendation
Using the -std= argument is recommended for several reasons:
References
The above is the detailed content of How Do I Choose the Right C Standard When Compiling with g ?. For more information, please follow other related articles on the PHP Chinese website!