Best Practices for Writing Safer C Code

Thomas Honold wrote an article published on EETimes giving 17 steps to safer C code. Not only this article provides tips to write safer C code, but I believe those steps are simply best practices when writing C code for embedded systems as they shorten the software life cycle by making it easier for a software team to write, debug and maintain code and by improving the software QA procedure. Here’s a summary of the 17 steps to achieve safer C code: Follow the rules you’ve read a hundred times: Initialize variables before use. Do not ignore compiler warnings. Check return values. Use enums as error types. Define an ENUM_MAX value at the end, so that the code to check the range does not have to be modified each time you add a new error code. Expect to fail Always assume there will be an error and set to default […]

Memfault IoT and embedded debugging platform