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
Release: 2024-12-06 12:19:12
Original
420 people have browsed it

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
Copy after login

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!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template