Home > Backend Development > C++ > body text

How to Determine the Default C Standard Used by g ?

DDD
Release: 2024-11-17 06:08:03
Original
712 people have browsed it

How to Determine the Default C   Standard Used by g  ?

C Standard Detection in g

In C , the standard compiler version may affect the behavior and compatibility of your code. When compiling with g , understanding the default standard is crucial.

Consider the following code snippet:

#include <fstream>
#include <string>

int main() {
    std::string filename = "input.txt";
    std::ifstream in(filename);

    return 0;
}
Copy after login

If you compile this code on Windows using the g example.cpp command, it may fail due to linker errors related to converting from std::string to const char*. However, specifying a specific C standard using g -std=c 17 example.cpp resolves this issue.

To determine the default C standard used by g , you can execute the following command:

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

For example, using this command on the Ubuntu 4.8.4 version of g , you would get the output:

#define __cplusplus 199711L
Copy after login

This indicates that the default C standard for this version of g is C 98 (199711L represents the November 1997 revision of the C standard).

It is recommended to always specify the desired C standard explicitly when compiling with g . This ensures that the code conforms to the intended standard and avoids potential compatibility issues that may arise from using an outdated or undesired standard.

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template