SEGGER C++ Library
With the SEGGER C++ Library, Embedded Studio provides all required features for efficient C++ applications according to the latest standards.
Overview
Embedded Studio supports application development in C and C++. Its C runtime library, based on emRun, provides all fundamentals, tweaked for fastest speed or smallest size. In addition, the C++ library provides all required features for efficient C++ applications.
The SEGGER C++ Library is a complete C++ standard library. It is specifically tweaked for embedded systems and applications. As a modern programming language, C++ is becoming increasingly important in the embedded sector offering developers more and more options. Considering this, the SEGGER C++ Library is constantly being further developed, meeting the most modern C++ standards.
As part of the Embedded Studio IDE, the SEGGER C++ Library is available out of the box and provides all features that makes object-oriented programming (OOP) fast and easy. Accompanying the ready-to-use toolchain (including compiler and linker) and the C runtime library of Embedded Studio, the SEGGER C++ Library completes the whole package. The user does not have to worry about configurations or implementation into the toolchain.
Key features
- Comprehensive C++ standard library
- Compatibility with common C++ standards, C++17
- Complete integration with the SEGGER C Runtime Library
- Dynamic memory management, tweaked for embedded systems
- Exception handling, including target unwinding on all supported targets
Library package
The SEGGER C++ Library is part of the Embedded Studio package and contains everything needed. It is available as a pre-built, ready-to-run library for all supported target architectures.
To limit the download and installation size of Embedded Studio, the library is supplied as an additional package. Embedded Studio takes care of downloading the package on demand specifically per each project’s selected target device.
For more information on how to include the SEGGER C++ Library, please visit our Wiki page which provides step-by-step instructions:
https://wiki.segger.com/Cpp_Support_in_Embedded_Studio
For details concerning the library packages, please visit:
https://studio.segger.com/packages/
Modern C++ features
Embedded Studio enables C++ development using modern C++ features. The included compilers are constantly updated to support the latest C++ language dialects. The SEGGER C++ Library implements classes and functions according to the C++ standards and supplements the language features. As of now, it incorporates the complete feature set of the C++17 standard defined by the International Organization for Standardization (ISO).
With the SEGGER C++ Library, Embedded Studio provides all standard C++ header files together with wrappers for the C runtime library headers. The implementation includes mangled names of standard C functions, such as cos(float) and cos(double) to its C equivalents cosf() and cos().
Dynamic memory allocation
Modern C++ applications rely on dynamic memory allocation. Objects are present in memory only while they are being used. Long-lived objects are usually created with “new” and destroyed with “delete”. While C++ takes care of calling objects’ constructors and destructors respectively, the regular C runtime library basically does the memory management.
The SEGGER C++ Library implements "new" and "delete" to use the alloc and free routines of the SEGGER Runtime Library, which provides efficient use of the heap memory, requiring the least overhead.
Exception handling
C++ defines the use of exceptions, in contrast to C programming where it is the user’s responsibility to manually recover from an error and pass errors up to all callers, or to run into a fault. Exception handling offers a systematic and robust approach to cope with errors that cannot be recovered from locally. Exceptions can be thrown in case of an error and are passed up the call stack up to a point where they are caught and handled.
When an exception is thrown in a try block, all objects constructed within the block need to be destroyed, and the stack is unwound. To provide exception support, the SEGGER C++ Library implements the target architecture-dependent stack unwinding for all supported architectures.
Exceptions require additional code and memory, which is a valuable resource on embedded targets. Since not every application needs it, Embedded Studio allows configuration to enable or disable exception support. Likewise, users can choose between two variants of the SEGGER C++ Library: the regular configuration which throws exceptions in case of an error, and the smaller configuration which does not throw.
Low-level support
C++ compilers define an application binary interface (ABI) which, for example, defines how objects are arranged, how name mangling works, or how virtual functions are implemented.
The SEGGER C++ Library implements the low-level functions of the C++ ABI which the compiler implicitly adds calls to in code generation. This enables the SEGGER C++ Library to be used out-of-the-box with the supported toolchain.