Disabling unwanted C++ features
You may have noticed that we used printf from the C standard library for printing debug information on standard output instead of std::cout from the C++ standard library. The reason is twofold – the implementation of the std::cout global object from ostream has a large memory footprint and it uses dynamic memory allocation. C++ works well with the C standard library, and using printf is a good alternative for resource-constrained systems.
We already discussed the exception handling mechanism, which often relies on dynamic memory allocation. Disabling exceptions in C++ is as easy as passing the appropriate flag to the compiler. In the case of GCC, that flag is –fno-exceptions. The same goes for Run-Time Type Information (RTTI). We can disable it with the –fno-rtti flag.
Disabling exceptions will result in calling std::terminate when an exception is thrown. We can replace the default terminate handler with our own implementation...