File names should use snake_case.
hello_world.c
useful_header.h
Preprocessor include guards should be the same as the file name, replacing
'.' with _
, with the addition of two underscores __
on either
side.
#define __SOME_FILE_H__ // some_file.h
Preprocessor macro names should use SCREAMING_SNAKE_CASE
#define I_AM_DEFINED
#define CONSTANT_FOO 1
#define MACRO_BAR(X) bar(X)
Variable names should use snake_case.
int some_var_name;
Pointers should be postfixed with _p
. A pointer to a pointer should be
postfixed with _pp
, and so on.
int* pointer_p;
int** double_pointer_pp;
Boolean variables should be signed int
s prefixed with b_
.
int b_boolean;
Array variables should be postfixed with _arr
, regardless of whether
array subscript notation or pointer notation is used.
Variables that are used to store the length of arrays should be named after
the array they are associated with followed by _arr_n
.
int array_of_ints_arr[];
size_t array_of_ints_arr_n;
float* array_of_floats_arr;
Character arrays used for the purpose of storing strings should be
postfixed with _str
.
Variables that are used to store the length of strings (excluding any
terminating character) should be postfixed with _len
.
char* a_string_str;
size_t a_string_len;
Function names should use snake-case. If a function takes no parameters, then
void
should be specified in the parameter list to conform to strict
prototypes.
void some_function(void);
struct
identifiers should be postfixed with _st
.
A single underscore _
is used to denote members of a struct
which
are not meant to be modified by the user.
struct struct_name_st {
int some_member_var;
int _readonly_member_var;
};
enum
identifiers should be postfixed with _en
.
All members of an enum
should be prefixed with the enum
's name in uppercase,
followed by the enum
member's unique name in snake-case.
An optional member at the end of an enum
may be desired in some cases to get the
maximum value of an enum
. This value identifer should be prixed with __MAX
.
enum enum_name_en {
ENUM_NAME_one,
ENUM_NAME_two,
ENUM_NAME_three,
// Optional
ENUM_NAME__MAX
};
Generally it should be preferred to use a symbol's fully qualified name, but
if a typedef
alias is necessary, then the identifier should be postfixed
with _ty
.
typedef type type_alias_ty;
Function pointer names should be prefixed with f_
.
void(*f_function_pointer)();