Home >Backend Development >C++ >How Can I Check for C 11 Support During Compilation?

How Can I Check for C 11 Support During Compilation?

Linda Hamilton
Linda HamiltonOriginal
2024-12-07 13:09:15431browse

How Can I Check for C  11 Support During Compilation?

Determining C 11 Support at Compile-Time

C programmers often need to determine if their compiler supports specific features of C 11 to ensure compatibility with their code. Here's how to achieve this:

Utilizing the __cplusplus Constant

Some compilers provide a constant named __cplusplus, which indicates the supported C standard version. The following example checks for C 11 support:

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

Leveraging Boost Macros

Another option is to use macros from the Boost library, which provides defines for specific C 11 features, such as:

  • BOOST_CXX11_VARIADIC_MACROS
  • BOOST_CXX11_THREADS
#ifndef BOOST_CXX11_VARIADIC_MACROS

#error "Your compiler doesn't support variadic templates."

#else

template <typename... DatatypeList>
class Tuple
{
    // ...
}

#endif

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