Can I reduce the size of C++ code ?

Q: Building my C++ code, I notice that it takes a lot of space, would it be possible to reduce the size code?

A: It is known that the size of C ++ code is bigger than C code.
RKit-ARM version 1.62.15.0334 and higher has options to reduce the code size by optimizing during the compilation and/or the link.

Note: options are enabled by default (normative) but they are rarely used or useless in embedded systems.

Below are some tricks to reduce your C++ code when building it:

1. Remove the demangle information (an automatic trace-like exceptions reporting):
It is huge and useless in embedded systems, even if using exceptions. Disable by default.

2. Remove the UART librariess if you don't use the UART or SWV for printf:

  • set printf linker option to “full GNU printf”
  • set putchar linker option to “no”

3. Enable the nano version of the C++ library (Linker).

4. Remove the rtti and exceptions support (unless you use them).
C++ exceptions are large and unused in embedded systems.