Barr Group TwitterBarr Group Vimeo

Rules:

3.2.a. The names of variables within a series of declarations shall have their first characters aligned.

3.2.b. The names of struct and union members shall have their first characters aligned.

3.2.c. The assignment operators within a block of adjacent assignment statements shall be aligned.

3.2.d. The # in a preprocessor directive shall always be located at the start of a line, though the directives themselves may be indented within a #if or #ifdef sequence.

Example:

#ifdef USE_UNICODE_STRINGS
#   define BUFFER_BYTES    128
#else
#   define BUFFER_BYTES    64
#endif
…
typedef struct
{
    uint8_t    buffer[BUFFER_BYTES]; 
    uint8_t    checksum;

} string_t;

Reasoning: Visual alignment emphasizes similarity. A series of consecutive lines each containing a variable declaration is easily seen and understood as a block of related lines of code. Blank lines and differing alignments should be used as appropriate to visually separate and distinguish unrelated blocks of code that happen to be located in proximity.

Enforcement: These rules shall be enforced during code reviews.

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.