C++ feature descriptions
When you write C++ source code for the IAR C/C++ Compiler for RISC-V, you must be aware of some benefits and some possible quirks when mixing C++ features—such as classes, and class members—with IAR language extensions, such as IAR-specific attributes.
Static data members of C++ classes are treated the same way global variables are, and can have any applicable IAR type and object attribute.
Member functions are in general treated the same way free functions are, and can have any applicable IAR type and object attributes. Virtual member functions can only have attributes that are compatible with default function pointers, and constructors and destructors cannot have any such attributes.
The location operator @ and the #pragmalocation directive can be used on static data members and with all member functions.
C++ supports templates according to the C++ standard. The implementation uses a two-phase lookup which means that the keyword typename must be inserted wherever needed. Furthermore, at each use of a template, the definitions of all possible templates must be visible. This means that the definitions of all templates must be in include files or in the actual source file.
A function type with extern"C" linkage is compatible with a function that has C++ linkage.
Example
extern "C"
{
typedef void (*FpC)(void); // A C function typedef
}
typedef void (*FpCpp)(void); // A C++ function typedef
FpC F1;
FpCpp F2;
void MyF(FpC);
void MyG()
{
MyF(F1); // Always works
MyF(F2); // FpCpp is compatible with FpC
}If interrupt functions use static class objects that need to be constructed (using constructors) or destroyed (using destructors), your application will not work properly if the interrupt occurs before the objects are constructed, or, during or after the objects are destroyed.
To avoid this, make sure that these interrupts are not enabled until the static objects have been constructed, and are disabled when returning from main or calling exit. For information about system startup, see System startup and termination.
Function local static class objects are constructed the first time execution passes through their declaration, and are destroyed when returning from main or when calling exit.
To handle memory exhaustion, you can use the set_new_handler function.
If you do not call set_new_handler, or call it with a NULL new handler, and operatornew fails to allocate enough memory, it will call abort. The nothrow variant of the new operator will instead return NULL.
If you call set_new_handler with a non-NULL new handler, the provided new handler will be called by operatornew if operatornew fails to allocate memory. The new handler must then make more memory available and return, or abort execution in some manner. The nothrow variant of operatornew will never return NULL in the presence of a new handler.
This is the same behavior as using the nothrow variants of new.
The C-SPY debugger has built-in display support for the STL containers. The logical structure of containers is presented in the watch views in a comprehensive way that is easy to understand and follow.
For more information, see General C-SPY debugger features.