C++ language extensions
When you use the compiler in C++ mode and enable IAR language extensions, the following C++ language extensions are available in the compiler:
In a
frienddeclaration of a class, theclasskeyword can be omitted, for example:class B; class A { friend B; //Possible when using IAR language //extensions friend class B; //According to the standard };In the declaration of a class member, a qualified name can be used, for example:
struct A { int A::F(); // Possible when using IAR language extensions int G(); // According to the standard };It is permitted to use an implicit type conversion between a pointer to a function with C linkage (
extern "C") and a pointer to a function with C++ linkage (extern "C++"), for example:extern "C" void F(); // Function with C linkage void (*PF)() // PF points to a function with C++ linkage = &F; // Implicit conversion of function pointer.According to the standard, the pointer must be explicitly converted.
If the second or third operands in a construction that contains the
?operator are string literals or wide string literals—which in C++ are constants—the operands can be implicitly converted tochar *orwchar_t *, for example:bool X; char *P1 = X ? "abc" : "def"; //Possible when using IAR //language extensions char const *P2 = X ? "abc" : "def";//According to the standardDefault arguments can be specified for function parameters not only in the top-level function declaration, which is according to the standard, but also in
typedefdeclarations, in pointer-to-function function declarations, and in pointer-to-member function declarations.In a function that contains a non-static local variable and a class that contains a non-evaluated expression—for example a
sizeofexpression—the expression can reference the non-static local variable. However, a warning is issued.An anonymous union can be introduced into a containing class by a
typedefname. It is not necessary to first declare the union. For example:typedef union { int i,j; } U; // U identifies a reusable anonymous union. class A { public: U; // OK ‑‑ references to A::i and A::j are allowed. };In addition, this extension also permits anonymous classes and anonymous structs, as long as they have no C++ features—for example, no static data members or member functions, and no non-public members—and have no nested types other than other anonymous classes, structs, or unions. For example:
struct A { struct { int i,j; }; // OK ‑‑ references to A::i and A::j are allowed. };The
friendclass syntax allows non-class types as well as class types expressed through atypedefwithout an elaborated type name. For example:typedef struct S ST; class C { public: friend S; // Okay (requires S to be in scope) friend ST; // Okay (same as "friend S;") // friend S const; // Error, cv-qualifiers cannot // appear directly };It is allowed to specify an array with no size or size 0 as the last member of a struct. For example:
typedef struct { int i; char ir[0]; // Zero-length array }; typedef struct { int i; char ir[]; // Zero-length array };An array can have an incomplete
struct,union,enum, orclasstype as its element type. The types must be completed before the array is used—if it is— or by the end of the compilation unit—if it is not.Mixed string literal concatenations are accepted.
wchar_t * str = "a" L "b";
A trailing comma in the definition of an enumeration type is silently accepted.
Except where noted, all of the extensions described for C are also allowed in C++ mode.
Note
If you use any of these constructions without first enabling language extensions, errors are issued.