14

This page lists 53 features that were new in C99 (i.e they are in C99 but not C89). Are all of these features also in C++? Even C++98?

If not, which of the features are in C++ and which are not?

user200783
  • 13,722
  • 12
  • 69
  • 135
  • Is there one specifically you wish to know about, or do you intend to use all 53 features and making sure they'll all work? – Tas Nov 28 '17 at 05:30
  • 1
    You may wish to add the features into the question yourself, in case the link dies. – Tas Nov 28 '17 at 05:31
  • 10
    I'd say that most of the new core language features of C99 are NOT in C++. VLA are not in C++. Compound literals are not in C++. Flexible array member is not in C++. Syntax like `void foo(int a[const static 5])` is not in C++. `restrict` is not in C++. And so on. Cores of these language have diverged irrevocably. There's never been any intent to keep them in sync. – AnT stands with Russia Nov 28 '17 at 05:31
  • Possible duplicate of [Which parts of C89 are not included in C++98?](https://stackoverflow.com/questions/47503880/which-parts-of-c89-are-not-included-in-c98) –  Nov 28 '17 at 05:47
  • 1
    This is broad, but someone could technically go through all 53 features and have a concrete answer, as AnT has already started doing, and it would be a very educational and constructive answer. I for one have never seen `a[const static 5]` before. Anyone could also go figure it out by themselves, but that's not the point. It's the same for many, many highly upvoted SO questions. – Millie Smith Nov 28 '17 at 06:34
  • 2
    @MillieSmith -- but [don't-ask](https://stackoverflow.com/help/dont-ask) suggests that questions should be "reasonably scoped." Asking someone to go through a list of 53 features in an answer seems to strain credulity for "reasonably scoped." – ad absurdum Nov 28 '17 at 06:56
  • 2
    Took 15 minutes to go through them. Sure, might have made some mistakes... But some C++ person could perhaps proof read. – Lundin Nov 28 '17 at 08:07
  • *Too broad*? If anything, this question is *too precise*; changing just one small part of it yields a completely different answer, where-as this question is actually *better* when expressed in a more broad sense, as it'll elicit *more* information and *also* answer those other similar questions. – autistic Dec 04 '17 at 02:27
  • This question is specifically about features of C99. It is not a duplicate of "[Which parts of C89 are not included in C++98?](https://stackoverflow.com/questions/47503880/which-parts-of-c89-are-not-included-in-c98)", which does not mention C99 at all. – user200783 Dec 04 '17 at 14:52
  • 2
    In years down the road, this good question will lose precision as C++ evolves. Consider titling the question to a specific version(s) of C++. (maybe the last two as of 2017.) – chux - Reinstate Monica Dec 07 '17 at 23:00

2 Answers2

27

The following C99 (ISO 9899:1999) features are fully supported by C++ (ISO 14882:2017):
(though library headers will be <cname> rather than <name.h>:

  • wide character library support in <wchar.h> and <wctype.h> (originally specified in ISO/IEC 9899:1990/Amd.1:1995)
  • type-generic math macros in <tgmath.h>
  • the long long int type and library functions
  • extended integer types
  • increased minimum translation limits
  • additional floating-point characteristics in <float.h>
  • remove implicit int
  • reliable integer division
  • universal character names (\u and \U)
  • extended identifiers
  • hexadecimal floating-point constants and %a and %A printf/scanf conversion specifiers
  • // comments
  • specified width integer types and corresponding library functions in <inttypes.h> and <stdint.h>
  • remove implicit function declaration
  • preprocessor arithmetic done in intmax_t/uintmax_t
  • mixed declarations and statements
  • new block scopes for selection and iteration statements
  • integer constant type rules
  • integer promotion rules
  • the vscanf family of functions in <stdio.h> and <wchar.h>
  • additional math library functions in <math.h>
  • treatment of error conditions by math library functions (math_errhandling)
  • floating-point environment access in <fenv.h>
  • IEC 60559 (also known as IEC 559 or IEEE arithmetic) support
  • trailing comma allowed in enum declaration
  • %lf conversion specifier allowed in printf
  • inline functions
  • the snprintf family of functions in <stdio.h>
  • idempotent type qualifiers
  • empty macro arguments
  • additional predefined macro names
  • _Pragma preprocessing operator
  • standard pragmas
  • __func__ predefined identifier
  • va_copy macro
  • additional strftime conversion specifiers
  • LIA compatibility annex
  • deprecate ungetc at the beginning of a binary file
  • remove deprecation of aliased array parameters
  • conversion of array to pointer not limited to lvalues
  • relaxed constraints on aggregate and union initialization
  • relaxed restrictions on portable header names
  • return without expression not permitted in function that returns a value (and vice versa)
  • macros with a variable number of arguments

The following C99 features have similar use in C++, but there are implementation differences and the languages are not code compatible:

  • restricted character set support via digraphs and <iso646.h> (originally specified in ISO/IEC 9899:1990/Amd.1:1995)
  • more precise aliasing rules via effective type
  • complex (and imaginary) support in <complex.h>
  • boolean type in <stdbool.h>
  • new structure type compatibility rules (tag compatibility)

The following C99 features are not supported by C++:

  • restricted pointers
  • variable length arrays
  • flexible array members
  • static and type qualifiers in parameter array declarators
  • compound literals
  • designated initializers
Lundin
  • 195,001
  • 40
  • 254
  • 396
  • Since I'm hardly a C++ guru, I'm almost certain to have goofed up several of these. Hence community wiki. Please edit if you find any mistakes and move them to the correct category! – Lundin Nov 28 '17 at 08:06
  • *macros with a variable number of arguments*, isn't that [variadic macros](macros with a variable number of arguments)? – NathanOliver Dec 06 '17 at 22:48
  • @NathanOliver Yes. These terms are taken from the C99 foreword. I just copy/pasted all the changes that were made in C99 from there. – Lundin Dec 07 '17 at 07:57
  • I think what @NathanOliver is referring to is that, since C++11, C++ supports variadic macros. So, should "macros with a variable number of arguments" in a different category? Or is your answer specific to the older C++98? – user200783 Dec 09 '17 at 12:14
  • @Lundin Sorry I messed up my link. Since C++11 [variadic macros](http://en.cppreference.com/w/cpp/preprocessor/replace) are supported. – NathanOliver Dec 09 '17 at 17:15
  • As written in the answer, and as per C++ tag policy, I'm assuming the current standard ISO 14882:2017. This is a community wiki, please feel free to fix any errors you spot. – Lundin Dec 11 '17 at 07:27
3

Flexible array members are not part of any C++ standard (and the dynarray proposal was not adapted in C++). And there are many other less used C99 features which are not in C++.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547