> But the compiler doesn't optimize out the constructor, right? It can't.
> In an RTOS of all places, that seems awfully expensive. One generally avoids wasted resources in embedded -- the trade-off is it requires more care during development.
The compiler has no issues "optimizing out" the constructor in my experience. The asm looks just like the equivalent C in all of the cases I've seen.
> I've never seen RAII work well in an embedded system. Not being able to handle exceptions or errors during destruction ruins everything.
I mean, we disallow exceptions anyway. And we use RAII for objects where there isn't a weird failure case to be handled like my example of thread priority guards.