Skip to content

club-rockets/coding-style

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

RockÉTS coding style

This file and repo dictates the coding style to use when contributing C code on Club RockÉTS repositories.

General

Identation

Code should be idented with 4 spaces.

Trailing whitespace

Code should not contain trailing whitespace but source files should end with a newline.

Braces

Braces should never be dropped, and should be placed on the same line as the condition, except for function names (K&R style).

// Good
int main()
{
    if (condition) {
        something();
    }

    do {
        // Stuff
    } while (true);
}
// Bad
void java() {
    if (condition)
        something();

    do
    {
        // Stuff
    }
    while (true);
}

Pointer alignement

Pointer types should be written with a space between the type name and the * (this means there is no space before the identifier).

// Good
int *a;
float *b, *c;

// Bad
int* a;
float* b,* c;

Complex Macros

Macros composed of more than one line should be wrapped in a do { ... } while (0) block.

#define DO_SOMETHING(param1, param2) \
    do {\
        function_alpha(param1);\
        function_bravo(param2);\
    } while (0)

Header guards

All header files should contain an header guard. The header guard define should be the file name in ALL_CAPS, with the . substituded for an _, and a trailing _ added.

#ifndef KARMAN_FILTER_H_
#define KARMAN_FILTER_H_
// karman_filter.h

#endif

Naming

Files

File should be named in snake_case.

Functions

Functions should be in snake_case. They should be prefixed with the module name.

// Good
int mti_set_config();
void karman_filter_data(int len, int *data);

// Bad
void PowerGet();
void doSomethingElse(int parameter);

Macros

Macros should be in ALL_CAPS.

#define PI 3.141592
#define DO_SOMETHING(param) do { something(param); } while (0)

Variables

Constant variables should be in ALL_CAPS. File and function scope variables should be named in snake_case.

const int SPEED_OF_LIGHT = 299792468;

int function()
{
    int param;
    float pi = 3.141592f;
}

About

Coding guidelines for RockÉTS C code.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published