Checking for C 11 Support
In C , determining if a compiler supports specific features of C 11 is crucial for ensuring compatibility. Some methods exist to perform this check at compile-time, including:
Using __cplusplus Constant
The __cplusplus constant, defined by the preprocessor, indicates the supported C standard version. For example:
#if __cplusplus <= 199711L #error This library needs at least a C++11 compliant compiler #endif
Using Boost Defines
Boost provides defines (__has_feature(feature_name)) that enable checking for specific C 11 features, such as:
#if __has_feature(cxx_automatic_resource_management) // C++11 has automatic resource management #endif
Example: Checking for Variadic Templates
Suppose you want to use variadic templates, a C 11 feature. You can check for its support using the following code:
#ifndef VARIADIC_TEMPLATES_SUPPORTED #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 Compiler Support?. For more information, please follow other related articles on the PHP Chinese website!