UNCLASSIFIED

Skip to content
Snippets Groups Projects

Barr C Checklist

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by James Orman
    Edited
    snippetfile1.txt 2.58 KiB
    []Use braces {} for conditional statements.
    []Do not abbreviate variable names.
    []Limit use of goto for one section of code.
    []Use const for variables that should not be modified.
    []operators need a space before and after. ex) if while switch return + - 
    []indentations are 4 spaces, do not use tab character (0x09)
    []blank line before and after each structured block of code such as if, while etc...
    []no non-printing characters such as CR (carriage return)
    []use snake_case for module names, functions, and variables
    []initialize variables before use
    []Do not use comma , operator with variable declarations.
    []Set variables to zero before and after usage. Zeroing after, increases code security.
    []Limit functions to 100 lines
    []Private functions are declared static
    []no variables in header files
    []do not use absolute file paths
    []The names of all new data types, including structures, unions, and enumerations, shall consist only of lowercase characters and internal underscores and end with ‘_t ’
    []Use the C99 type names float32_t , float64_t, and float128_t 
    []Append an ‘f ’ to all single-precision constants (e.g., pi = 3.141592f )
    []many goto statements jump to only one label
    []minimize and avoid use of goto if possible
    []Ensure double precision
    #include <limits.h>
    #if (DBL_DIG < 10) // Ensure the compiler supports double precision.
    # error “Double precision is not available!”
    #endif
    
    []Prevent or stop struct padding
    typedef struct
    {
    uint16_t count; // offset 0
    uint16_t max_count; // offset 2
    uint16_t _unused; // offset 4
    uint16_t enable : 2; // offset 6 bits 15-14
    uint16_t b_interrupt : 1; // offset 6 bit 13
    uint16_t _unused1 : 7; // offset 6 bits 12-6
    uint16_t b_complete : 1; // offset 6 bit 5
    uint16_t _unused2 : 4; // offset 6 bits 4-1
    uint16_t b_periodic : 1; // offset 6 bit 0
    } timer_reg_t;
    // Preprocessor check of timer register layout byte count.
    #if ((8 != sizeof(timer_reg_t))
    # error “timer_reg_t struct size incorrect (expected 8 bytes)”
    #endif
    
    []use type bool for boolean
    #include <stdbool.h>
    ...
    bool b_in_motion = (0 != speed_in_mph);
    
    []Use functions instead of parameterized macros.
    []All functions that encapsulate threads of execution (a.k.a., tasks, processes) shall be given names ending with “_thread ” (or “_task ”, “_process ”).
    []Interrupt Service Routines need special handling. See the Barr Guide.
    []No 'magic numbers'. Replace constants with meaningful variables.
    
    #Other checks not related to BARR C
    []No use after free
    []Memory is managed properly
    []Check for Errors after memory allocation
    []Prevent buffer overflow
    []Prevent integer overflow/underflow
    0% or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment