Search code examples
c++stlembeddedavr

Why Embedded C++ compilers not support exceptions?


I was writing a library to embedded systems and I bumped into no STL standard library easy found.

But the worst news I receive is no exception support by compiler. Atmel reference manual show this

Why not support exceptions on embedded environment?

It's simple make impossible to use a lot of libraries written in C++. C++ is closely linked with exceptions, like with the new operator!


Solution

  • Obviously, nobody but the people that produce that compiler can really answer that question.

    My best guess is that exceptions are both space- and time-consuming (time is only a real problem when the code throws, but space is needed for the unwind tables always, and can easily be about the same size as the overall code) for the compiled code, coupled with "rather difficult to implement", it's perhaps not the highest item on the list for the compiler developers, and thus not yet implemented. Whether it WILL be at some point in the future is obviously up to Atmel or whoever they subcontract to make their compiler.

    I'm not an expert on Atmel C++ implementation, but I would be VERY surprised if the compiler supports throw, but not try/catch - since that would be about as useful as a screwdriver made from chocolate, when trying to fix the heater in a sauna that is stuck on full heat.

    If you use the -fno-exceptions, the compiler should error if you have any throw in the code. And the STL can be compiled with -fno-exceptions - as that's how I compile my compiler code.