Home  >  Article  >  Backend Development  >  What is the Default C Standard Used by g ?

What is the Default C Standard Used by g ?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-20 01:35:02767browse

What is the Default C   Standard Used by g  ?

Default C Standard in g

When compiling code with g , a C compiler, it's essential to know the default standard used. By understanding the default standard, you can ensure your code compiles and functions correctly.

Identifying the Default Standard

To identify the default C standard used by g , execute the following command:

g++ -dM -E -x c++ /dev/null | grep -F __cplusplus

This command outputs a macro definition that indicates the value of __cplusplus, which corresponds to the supported C standard version. For example, a result like #define __cplusplus 199711L indicates C 98.

Default Standard Activation

In g versions earlier than 4.7, the default standard is C 98. However, in later versions, the default standard is determined by the compiler flags. If no standard is specified, it defaults to C 98.

Recommended Standard Specification

It's generally recommended to explicitly specify the C standard when compiling code. By using the -std flag, you can set the desired standard, ensuring compatibility with your code's requirements.

For instance, if your code requires C 17 features, it's prudent to use the g -std=c 17 command, as illustrated in the example provided. This approach ensures that the code is compiled and linked properly.

By understanding the default C standard in g and the recommendation to explicitly specify the standard, you can ensure your code compiles successfully and behaves as intended.

The above is the detailed content of What is the Default C Standard Used by g ?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn