One of the worst things about embedded development (especially in C) is
receiving a return value of -1 or unknown_error from a function, with no
other information about why the failure took place. It provides no information
about where the error bubbled up from!
Be aware that the memset call is likely to be removed if optimizations are enabled. With GCC, you can use the -fno-builtin-memset flag to prevent this, but that may pessimize the generated code elsewhere.
Thanks for the inspiring article! I would like to ask what is meant by “state machine generators” in this article. Which ones do you prefer to use? Are you planning an article on this topic?
I’m really glad to see that other fellow embedded software developers reach similar conclusions about facing software errors head on (otherwise known as Design by Contract – DbC).
In a shameless self-promotion, I’d like to mention my articles and blogs about the same subject matter: