Paparazzi UAS  v5.15_devel-164-g81d4ceb
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
C Style Guide

This page contains guidelines for writing new C source code for the Paparazzi project.

If you are using Eclipse, you can use Eclipse code style located in the repository (paparazzi_code_profile_eclipse.xml)

Formatting Guide

  • remove any trailing white space at the end of lines.
  • use 2 spaces for indentation; do NOT use tabs.
  • use Unix line endings ('\n'); do NOT use DOS endings ('\r\n')
  • limit code length to 100 chars per line
  • limit adjacent empty lines to at most two (2).
  • remove any trailing empty lines at the end of source files
  • do not "comment out" code from the tree; instead, one should either:
    1. remove it entirely (git can retrieve the old version), or
    2. use an #if/#endif block.

Naming Rules

  • most identifiers must use lower-case letters (and digits) only.
    • macros should use upper-case letters (and digits) only.

Type Guidelines

  • use the types from <inttypes.h>:
    • int8_t, int16_t, int32_t, or int64_t: signed types of specified size
    • uint8_t, uint16_t, uint32_t, or uint64_t: unsigned types of specified size


  • static inline functions should be prefered over macros in most cases:
    /* do NOT define macro-like functions like this... */
    #define CUBE(x) ((x) * (x) * (x))
    /* instead, define the same expression using a C99 inline function */
    static inline int cube(int x) { return x * x * x; }
  • Functions should be declared static unless required by other modules
    • define static functions before first usage to avoid forward declarations.
  • Functions should have no space between its name and its parameter list:
    int32_t f(int32_t x1, int32_t x2) {
    int32_t y = f(x1, x2 - x1);

Switch statements

  • specify a default case
  • prefer an enum over defines for the different states
    enum state {
    STATE_FOO = 1,
    STATE_BAR = 2
    switch (state) {
    case STATE_FOO:
    case STATE_BAR:

If statements

  • return statement on the new line even for ""simple if"" case
    if (TRUE) {
    return 1;
    if (x < other.x) {
    return -1;
    else if (x > other.x) {
    return 1;
    else {
    return 0;

Preprocessor directives

  • For conditional compilation use #if instead of #ifdef. Someone might write code like:
    #ifdef USE_FOO
    Someone else might compile the code with turned-off foo info like:
     gcc stuff.c -DUSE_FOO=0
    So use #if not #ifdef to turn a feature on or off. This works fine, and does the right thing, even if USE_FOO is not defined at all (!)
    #if USE_FOO
  • If you really need to test whether a symbol is defined or not, test it with the defined construct.