简体   繁体   中英

Does C++11 support new features of C11?

I have recently explored in C11 and many new features makes me code in C more easily. I am wondering ALL these features are officially supported by C++11. My concern is not about implementation or compiler issues but new C++ standard.

No, C++11 does not support ALL the features of C11. It does not even support all the features of C99. Variable-length arrays, for example, were introduced in C99, but C++ does not yet support them. See this question for details.

Among the major additions, two are shared between C11 and C++11: threads and atomics. I think also the new memory sequencing model is shared between the two, but I don't know C++11 well enough to assert that with certainty.

One major addition to C11 will probably never been shared by C++: type generic expressions with _Generic . For many of the use cases of that, in particular function overloading, there are already C++ constructs that implement that. Other more elaborate use cases such as detection of compile time integer constant expressions are not covered by C++. C++1 has constexpr , but other than the name might suggest this is not a tool to determine if an expression is a constant expression, but to specify that an object or a function return is constant. Generating completely different code for the two cases (constant and non-constant) doesn't seem possible.

No only that _Generic is not needed for the main use cases in C++, it also relies heavily on macro programming in the preprocessing phase. Since macros are frowned upon by large parts of the C++ community adding that would certainly not find consensus.

The C++11 standard references the C99 standard, particularly for the C standard library.

C++11 supports some, but not all, of the features that are in C99 but not in C90. (Some C99-specific features either are supported differently in C++, or were not deemed suitable.)

C11 added a number of features on top of C99; most of those new features were not also added to C++.

One notable exception to this is thread support ( <threads.h> in C11, <thread> in C++11). I haven't looked at this closely enough to know how similar they are.

(C11 also made some of its new features, as well as some C99 features, optional ; that's also not reflected in C++.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM