C PROGRAMMING

# C Naming Conventions

Article by:

## Variables

All local variables (variables within a function) begin with a lower-case letter and use camel-case, including function pointers. Only the first letter in an acronym is capitalised, e.g.

 1 2 3  void MyFunction() { uint8_t activeGpsAnt; } 

All file-level and global variable use the same syntax except with an underscore in front of them.

 1 2 3 4 5  uint8_t _activeGpsAnt; void MyFunction() { // code here... } 

## Functions

Functions start with the file/module name, an underscore, and then a description. All functions use camel-case and begin with a capital letter. For example, a function in a file called Gps.c would look like…

 1  void Gps_GetLocation(); 

## Typedefs

Typedefs aways end in _t. The helps the reader instantly distinguish a data type from anything else, and also serves to distinguish user defined data types (e.g. uint8_t, myType_t) from system data types (e.g. char, double, int).

## Acronyms

When it comes to capitalisation rules, acronyms are treated if they were a standard word, and only the first letter of the acronym is capitalised. For example, if you had a GPS variable, it would be named:

 1  bool gpsEnabled = true; 

Similarly, for functions:

 1  Gps_SetEnabled(); 

## Authors

### Geoffrey Hunter

Dude making stuff.