Barr Group TwitterBarr Group Vimeo


The following C coding rules relate to source files (i.e., files ending in .c):

Rule 4.3.a.) Each source file shall include only the behaviors appropriate to control one “entity”. Examples of entities include encapsulated data types, active objects (i.e., tasks or state machines), peripheral drivers (e.g., for a UART), and communication protocols or layers (e.g., ARP).

Rule 4.3.b.) Each source file shall be comprised of some or all of the following sections, in the order listed:

  • file comment block;
  • #include statements;
  • data type, constant, and macro definitions;
  • static data declarations;
  • private function prototypes;
  • public function bodies; then
  • private function bodies.

Rule 4.3.c.) Each source file shall always #include the header file of the same name (e.g., file adc.c should #include “adc.h”), to allow the compiler to confirm that each public function and its prototype match.

Rule 4.3.d.) Absolute paths shall not be used in #include statements.

Rule 4.3.e.) Each source file shall be free of unnecessary #include statements referring to unused .h header files.

Rule 4.3.f.) No source file shall #include another source file. (That is, #include should only be used to incorporate a .h header file.)


The purpose and internal layout of a source file module should be clear to all who maintain it. For example, the public functions are generally of most interest and thus appear ahead of the private functions they call. Of critical importance is that every function declaration be matched by the compiler against its prototype.




Prior to each build, an automated tool shall scan source files to ensure they #include their own header file but not unused header files. PC-Lint is an example of a tool that can be configured to perform the second check automatically.

What’s happening and how it’s done. Get in the know.

Sign Up for Our Newsletter

Receive free how-to articles, industry news, and the latest info on Barr Group webinars and training courses via email. 

To prevent automated spam submissions leave this field empty.