News for hackers. Stuff that matters.
Re:Practical Guide to Bare Metal C++ by ryandrake on Friday June 02, 2017 @02:30PM (#14472269)
Yea, I've always wondered, for shops that try to make that "C++ but without exceptions" policy work, how do you handle things like vector::push_back() or map::operator[] failing? Just throw up your hands and crash?
Re:Practical Guide to Bare Metal C++ by astrobe_ on Friday June 02, 2017 @02:51PM (#14472412)
I didn't read the book but if you're "bare metal" you want to avoid dynamic allocations in the place. Secondly, if you really run out of memory then you've screwed up something really badly and yes, in these situations your best option is to let the watchdog eat your poor carcass.
Re:Practical Guide to Bare Metal C++ by Gibbon1 on Friday June 02, 2017 @04:12PM (#14472939)
What you really want to do in these cases is log debugging info to a noinit section of memory or nonvolatile memory and then reset the processor. Then the firmware can check for and report any logged errors on startup. If you do this religiously you might make it to fifty with most of your hair.
Re:Practical Guide to Bare Metal C++ by monocasa on Friday June 02, 2017 @04:17PM (#14472973)
Also, for those programmers who have some input on the EE's designs, a stuff option for MRAM is amazing. It's essentially equivalent to battery backed SRAM, but one chip. We stick logs and hardware exception stack traces/register dumps in there on dev units.
Re:Practical Guide to Bare Metal C++ by monocasa on Friday June 02, 2017 @03:33PM (#14472707)
We at least just don't use the STL. We have an in house data structures library that's almost entirely intrusive.

One of the nice things about C++ is that the STL isn't using special case backdoors in the language, so if it doesn't work for your use case you can write your own data structures and have full language support.

Re:Practical Guide to Bare Metal C++ by maxxxxx on Friday June 02, 2017 @02:36PM (#14472312)
Seems to me if vector::push_back fails you are already deep into memory problems. I may put a global catch around most code to avoid crashes but I think once push_back fails, a lot of other stuff won't work either.
Re:Practical Guide to Bare Metal C++ by ensiferum on Friday June 02, 2017 @02:49PM (#14472391)
C++ can work but yeah, you really can't use the STL stuff since the API doesn't leave you other choice but to abort() if an exception was to be thrown.

If you want some other strategy then you have no choice but to implement your own containers with APIs that can support such operation.

Re:Practical Guide to Bare Metal C++ by to3m on Friday June 02, 2017 @05:21PM (#14473410)
Windows, OS X - let it crash

Linux - malloc never fails, so how would you know?

Xbox/PS2/PS3/Wii/etc. - bring up a screen that says "disc error"

iOS - the system will already have killed the process long before it's an issue