embedded software boot camp

Coding Standard Rule #5: Only use Comments for Commenting

Monday, March 30th, 2009 by Michael Barr

This is the fifth in a continuing series of blog posts describing simple coding rules that help keep bugs out of embedded C programs.

Rule: Comments shall neither be nested nor used to disable a block of code, even temporarily. To temporarily disable a block of code, use the preprocessor’s conditional compilation feature (e.g., #if 0 … #endif).

Example (don’t):
/*
a = a + 1;

/* comment */
b = b + 1;
*/

Reasoning: Nested comments and commented-out code both run the risk of allowing unexpected snippets of code to be compiled into the final executable. This can happen, for example, in the case of sequences such as the above.

Coding Standard Rule #4
Coding Standard Rule #6

These rules are excerpts from the Embedded C Coding Standard book.

Tags: , , ,

Leave a Reply