6

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.

jxh
  • 69,070
  • 8
  • 110
  • 193
flee
  • 493
  • 3
  • 7

3 Answers3

5

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.

Community
  • 1
  • 1
verbose
  • 7,827
  • 1
  • 25
  • 40
  • Variable-length arrays are slated for C++14 (just to give a timeframe to your statement). – zneak Sep 11 '13 at 03:12
  • @zneak: No, "arrays of runtime bound" being considered for C++ are not the same as C's VLAs. – Ben Voigt Sep 03 '14 at 23:26
  • @BenVoigt, [N3820](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3820.html#dcl.array) includes an example of the form `int foo[n]` with a non-constant `n`. Which differences should I be aware of? I see that it's no longer slated for C++14, though. – zneak Sep 04 '14 at 01:16
  • @zneak: "arrays of runtime bound" proposal in C++ are not allowed as arguments to `sizeof` or `decltype`. In C99, sizeof is a runtime operation when used on VLAs. I've heard there are other differences too, which I can't remember offhand. – Ben Voigt Sep 04 '14 at 04:42
2

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.

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
  • downvoted. C++11 can detect compile-time constant expressions with `constexpr`. – TemplateRex Oct 02 '13 at 08:03
  • @TemplateRex, I will look into that, in how that compares to the C feature. Downvoting for such a thing without giving me the time for correction, seems a bit extreme. Are you by any chance the one who is chasing me down the last day and downvoting on several old answers that I gave years ago? – Jens Gustedt Oct 02 '13 at 08:23
  • no, I try to always leave a comment, and I usually check back if there is an update on the answer, so that I can withdraw any downvotes. Regarding the other downvotes, I think you got a few people in the C++ chat Lounge upset last night with your tag editing in [this question](http://stackoverflow.com/q/19120326/819272), where the two topvoted answers (including one of mine) were also downvoted at the same time (*without* comment). – TemplateRex Oct 02 '13 at 08:26
  • @TemplateRex, ok, thanks for the notice. The fact is that I was a bit upset, too, that this question was taken by "force" by the C++ community. – Jens Gustedt Oct 02 '13 at 08:33
  • There wasn't anything by force, but rather by coincidence: the question got posted in the Lounge, there were no tags there at the time (at least not by the OP) and then one guy posted a C++ metaprogramming answer, then a C++11 constexpr version followed, and then I posted a C++14 constexpr answer. All with the *intention of helping both the OP and future readers*. Only then it got clear that the OP was programming in C, and he has rolled back the edits today. Which is his right, but I think the question is also useful for C++ users, so downvoting without comment is also a bit extreme there. – TemplateRex Oct 02 '13 at 08:36
  • 1
    oh and BTW, there is no such thing as *the* C++ community. As Stroustrup says: "nobody knows what most C++ programmers are doing". In fact, there is even a [Boost.Preprocessor](http://www.boost.org/doc/libs/1_54_0/libs/preprocessor/doc/index.html) library that is most often used by hardcore template-metaprogrammers to get the job done. It's not an ideological war, simply finding the right tools. – TemplateRex Oct 02 '13 at 08:40
1

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

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • 2
    My understanding is that C11 added threading support, both in the form of language support and components use to deal with threads and synchronization primitives. I think all of these features are C++ although the specifications are not necessarily identical between C and C++. – Dietmar Kühl Sep 06 '13 at 00:04
  • There were a bunch of other little things, too, like anonymous structures, no return functions, some type generic expressions, and the like. And, most importantly of all, it finally got rid of `gets()`. – Crowman Sep 06 '13 at 00:12
  • C11 added C++11 thread support (and atomics) more than the opposite ;) – J.N. Sep 06 '13 at 06:03