Naming Convention¶
General Rules¶
- English names shall be used.
- Descriptive names like
total_amountare preferred over abbreviations liketa.
Variables¶
- Use
snake_case.
Functions¶
- Use
snake_case.
Typedefs¶
- Use
CamelCasefor structs, enums, and other typedefs.
Struct Members¶
- Use
snake_case.
Enums¶
- Enum type name →
CamelCase - Enum values →
UPPER_CASE - Assign actual values to the enum values.
typedef enum SystemState {
SYSTEM_STATE_INIT = 0,
SYSTEM_STATE_RUNNING = 1,
SYSTEM_STATE_ERROR = 2
} SystemState;
Macros¶
- Use
UPPER_CASEwith underscores.
#define MAX_BUFFER_SIZE 256
#define DEFAULT_TIMEOUT_MS 1000
#define MIN(a, b) ((a) < (b) ? (a) : (b))
Constants¶
- Constants are treated like variables →
snake_case.
Include Guards¶
Every header file must use include guards.
- Uppercase
- File path based
- _H suffix
- No leading/trailing underscores
- No double underscores
Include Order¶
The include order shall be following.
- Own header
- C Standard libaries headers
- Third-Party headers
- Project headers
#include "motor_controller.h"
#include <stdint.h>
#include <stdbool.h>
#include "can_bus.h"
#include "pwm_driver.h"
File Naming¶
- File names use
snake_case. - One module per
.c/.hpair.
Examples:
motor_controller.cmotor_controller.hcan_bus.ccan_bus.h
Pointer Style¶
- The
*belongs to the name.
Visibility Rules¶
- Public API functions are declared in header files.
- Internal functions are declared
staticand remain inside the.cfile.
Booleans¶
-
Use
<stdbool.h>. -
Prefix boolean variables with:
-
is_ has_can_should_