Increasing embeddability of such C++ projects
There are two points which such "embeddable" projects (asmjit, etc.) usually try to provide:
- Zero dependencies - no external libraries, no STL/RTTI - easy to embed and/or link statically.
- Doesn't use exceptions internally, but allows to attach a "throwable" error handler (your choice).
My question is, whether you could also add these features? I would love to see them landing.
Thanks for the inquiry. So first let me say that SaferCPlusPlus was not designed to target platforms with the "traditional" embedded restrictions you mentioned. That said, as embedded software becomes more complex, and static verification less realistic, I can see the need for more scalable safety mechanisms, perhaps like SaferCPlusPlus.
Ok, so let me address your second point first: SaferCPlusPlus supports alternative (non-exception) error handling. Upon encountering a run-time error SaferCPlusPlus elements call a function macro named "MSE_CUSTOM_THROW_DEFINITION(x)". By default, the macro throws an exception, but you can redefine that macro to any code you desire. So for example, in the msetl_example.cpp file, near the top, there is a commented out line:
//define MSE_CUSTOM_THROW_DEFINITION(x) std::cerr << std::endl << x.what(); exit(-11)
Replacing the // with a # will cause the program to print out an error message and terminate instead of throwing an exception upon encountering an error. Just redefine the macro before including the SaferCPlusPlus header files.
The dependency on the standard library is a bit trickier. I presume that one reason the standard library is not available on some embedded platforms is due to the restriction on dynamically (heap) allocated memory. But both the standard library and SaferCPlusPlus have a useful subset that does not require dynamic allocation. I think the easiest solution would be to create a separate "embeddable" version of the SaferCPlusPlus library, by simply stripping out the elements that require dynamic allocation (like the vectors), and providing implementations of the remaining required standard library features (like std::array<>). Depending on license compatibility, presumably the source code for those implementations could simply be copied from the standard library itself. ("Registered" pointers would also need to be slightly modified to never resort to dynamic memory.)
As to whether or not I could provide this "embeddable" version - maaaybe in the future, but probably not any time soon. (In terms of this project, I'm currently working on auto-translation of native C/C++ code, and that might take a while.) The best bet would be if some other motivated soul wanted to undertake the task. I'd be happy to provide any needed advice though. :)