embedded software boot camp

Coding Standard Rule #3: Use static to Enforce Encapsulation

Thursday, March 26th, 2009 by Michael Barr

The third in a continuing series of blog posts about simple rules for keeping bugs out of embedded software written in the C programming language.

Rule: C’s static keyword shall be used to declare all functions and variables that do not need to be visible outside of the module in which they are declared.

Reasoning: C’s static keyword has several meanings. At the module-level, global variables and functions declared static are protected from inadvertent access from other modules. Heavy-handed use of static in this way thus decreases coupling and furthers encapsulation.

Coding Standard Rule #2
Coding Standard Rule #4

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

Tags: , , ,

Leave a Reply