Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C++11 support new features of C11?

Tags:

c++

c

c++11

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.

like image 359
flee Avatar asked Sep 05 '13 23:09

flee


People also ask

What are the new features of C11 standard?

C11 eliminates these hacks by introducing two new datatypes with platform-independent widths: char16_t and char32_t for UTF-16 and UTF-32, respectively (UTF-8 encoding uses char, as before). C11 also provides u and U prefixes for Unicode strings, and the u8 prefix for UTF-8 encoded literals.

Is C11 newer than C99?

C11 (formerly C1X) is an informal name for ISO/IEC 9899:2011, a past standard for the C programming language. It replaced C99 (standard ISO/IEC 9899:1999) and has been superseded by C17 (standard ISO/IEC 9899:2018).

What is the difference between C99 and C11?

C11 looked to address the issues of C99 and to more closely match the C++ standard, C++11. It changes some C99 features required to optional. Some of the features include variable length arrays and complex numbers. This makes it easier for compiler vendors to meet C11's required function set.

How do I know if G ++ supports C++11?

To see if your compiler has C++11 support, run it with just the --version option to get a print out of the version number. Do this for whichever compiler(s) you wish to use with Rosetta. Acceptable versions: GCC/g++: Version 4.8 or later.


3 Answers

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.

like image 146
verbose Avatar answered Sep 22 '22 01:09

verbose


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.

like image 38
Jens Gustedt Avatar answered Sep 19 '22 01:09

Jens Gustedt


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++.)

like image 37
Keith Thompson Avatar answered Sep 21 '22 01:09

Keith Thompson