0

Is there any advantage of using the noexcept specifiers of C++ while coding for an embedded system?

  • Does it make the binary smaller?
  • Does it make the code run faster?
  • How does it differ from the GCC's -fno-exceptions flag? Does using that flag marks every function as noexcept?
Caglayan DOKME
  • 948
  • 8
  • 21
  • 6 questions here. Perhaps narrow the list? – chux - Reinstate Monica Jul 16 '21 at 15:27
  • What have you tried? What have you measured? Consider that every Embedded System is different or unique. Some things that work with one system may not work or have the same impact on another system. Time to have the compiler print out the assembly language. Time to break out the oscilloscope on some test points and measure the efficiency. – Thomas Matthews Jul 16 '21 at 15:47
  • @ThomasMatthews You are right! I should've done them all. – Caglayan DOKME Jul 16 '21 at 15:59
  • @chux-ReinstateMonica Aren't they closely related to each other? – Caglayan DOKME Jul 16 '21 at 15:59
  • 1
    Just recently, I fiddled with `noexcept` (to become familiar with it) and noticed that 1.) `noexcept` doesn't prevent that you can call a possibly throwing function (i.e. no diagnostic). 2.) Wrapping function calls in the body of a `noexcept` function with a `try {` and `} catch (...) { }` (if you are paranoid like me) might be recognized and optimized by the compiler. [Demo on Compiler Explorer](https://godbolt.org/z/oaE855bvf) (Remove the `noexcept` from `something()` to see the difference.) – Scheff's Cat Jul 16 '21 at 16:00

0 Answers0