Home >Backend Development >C++ >How Can I Check for C 11 Compiler Support at Compile Time?

How Can I Check for C 11 Compiler Support at Compile Time?

Susan Sarandon
Susan SarandonOriginal
2024-12-06 12:19:12441browse

How Can I Check for C  11 Compiler Support at Compile Time?

Detecting C 11 Support during Compilation

Question:

How can you determine at compile-time whether your compiler supports specific features of the C 11 standard?

Answer:

One reliable method is to use the __cplusplus constant, which C compilers should set to reflect the version of the standard they support. For example:

#if __cplusplus <= 199711L
  #error This library needs at least a C++11 compliant compiler
#endif

This code will generate an error if the compiler's C version is less than or equal to 199711L, indicating that C 11 support is not available.

However, some vendors may not update __cplusplus immediately after implementing partial C 11 support. In such cases, using Boost's defines is still recommended for granular detection of specific C 11 features.

The above is the detailed content of How Can I Check for C 11 Compiler Support at Compile Time?. 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