User:Tacvek/C++0x
This page is a very rough attempt to create a guide to the new features of C++09 for people already familiar with c++03. It is based on n2606.pdf
TODO:
- Research the unknowns.
- Mention the type-generic header inclusion.
- Other headers added like the wchar header.
C99 Compatibility
[edit]Boolean Datatypes
[edit]C99 has a _Bool datatype that is generally used via the 'bool' macro (as well as true and false macros) found in <stdbool.h>. These definitions are compatible with the c++ keywords bool, true, and false.
Therefore, the C++0x standard adds a <stdbool.h> and <cstdbool> headers for compatibility. These headers simply define the __bool_true_false_are_defined macro as per the C99 standard.
The C++0x standard does not include the _Bool keyword. This does not hurt compatibility significantly, as few C programs use that keyword directly.
Complex Numbers
[edit]TODO
C99 Preprocessor additions
[edit]C++0x supports the _pragma keyword from C99. It also includes support for variable-length argument macros using __VA_ARGS__ (like in C99). I've not yet determined if it supports empty macro arguments or VARGS macros.
<stdint.h>
[edit]C++0x includes <stdint.h> of C99, as well as a <cstdint> header, with the typedefs in the std namespace.
long long ints
[edit]C++9x includes the C99 'long long datatype (as well as the more explicit long long int), as well as it's unsigned variation. It also includes the relevant additions to <limits.h> and <climits>. However, _Longlong and _ULonglong marcos/typedefs required by C++03TR1 are not included in C++0x. I'm not sure if c++0x includes the new type specifiers for printf and scanf.
__func__
[edit]C99's __func__ predefined value is present, containing an implementation defined string.
Trailing comma in enums
[edit]C99 Unclear features
[edit]Array Parameter Qualifier
[edit]It is not clear to me if the array parameter qualifier feature of C99 is in C++0x. For example:
void myfuncc(int t[const])
or
void baz(char s[static 10])
Compound literals
[edit]I've yet to determine if C++0x supports C99's compound literals.
Designated initializers
[edit]I've yet to determine if C++0x supports C99's designated initializers.
Variable Length Arrays
[edit]I've yet to determine if C++0x supports C99's variable length arrays.
Flexible Array Member (struct hack)
[edit]I've yet to determine if C++0x supports C99's Flexible array member feature.
restrict
[edit]I've yet to determine if C++0x supports C99's restrict feature.
C99 Features not included in C++0x
[edit]Hexadecimal floating-point literals
[edit]Why not?
One could almost implement this as a user-defined literal, but not quite. That seems odd to me.
New Features
[edit]angle bracket fix
[edit]typeof improvements
[edit]explicit conversion operators
[edit]constexpr
[edit]Type Determinism
[edit]TODO:
- Explain uses
- Provide examples
If a variable is declared with a specific initialization, it may use the specifier auto without a type specifier, and the compiler will determine the type of the right hand side of the initialization, and use that as the type.
There is a new pseudo-function keyword decltype, it takes as an argument an expression. It determines the type of the expression result at compile time. It functions as though it were replaced with the correct type specification for the result type of the expression. (CHECKME: I think it can be used where ever a type name can be used).
concepts
[edit]intialization lists
[edit]uniform initialization
[edit]range based for loops
[edit]lambda expressions/functions
[edit]alternative function syntax
[edit]function construction delegation
[edit]nullptr
[edit]To fix the issue of NULL being both an integer and a pointer type, and to make the name even clearer, there is a new keyword nullptr. It designates a constant r-value of a new unnamed datatype. (The datatype can have a name, but it must be using an implementation reserved name, or be otherwise inaccessible, such as defined in an unnamed namespace.) It is effectively a simple POD struct with implicit conversion operators to any pointer or pointer to member datatype. (Either by templated member functions, or by compiler magic.) While it is not expected to be very useful, the <cstddef> header will contain a new typedef of the form typedef decltype(nullptr) nullptr_t; or equivalent.