Tactility/CODING_STYLE_C.md
Ken Van Hoeylandt d551e467b8
Moved and renamed files for consistent C code style (#463)
* **Documentation**
  * Added new C coding style guide detailing naming conventions for files, directories, macros, constants, variables, functions, and type definitions with illustrative examples.
  * Updated C++ coding style documentation with clarifications on C naming conventions and header directory organization patterns.

* **Refactor**
  * Updated header include paths throughout the codebase to use lowercase naming conventions consistently.
2026-01-27 20:17:33 +01:00

1.4 KiB

C coding Style

Naming

Files

Files are lower snake case.

  • Files: ^[0-9a-z_]+$
  • Directories: ^[0-9a-z_]+$

Example:

some_feature.c
some_feature.h

Folders

Project folders include:

  • source for source files and public header files
  • private for private header files
  • include for projects that require separate header files

Macros and consts

These are all upper snake case:

#define MY_CONST 1
#define PRINT_SOMETHING() printf("something")
const int ANOTHER_CONST = 1;

Variables

Variable names and function parameters are lower snake case:

int some_variable;

Enumerations and Structs

Enums and struct types are upper camel case. Its fields use lower snake case.

struct ThreadData {
    int some_attribute;
};
enum SomeResult  {
    Ok,
    NotSupported,
    Error
};

Function names

Function names are lower snake case.

Example:

void get_limit() {
    // ...
}

If a set of functions relates to a struct, the CamelCase struct name is converted to a snake_case_ prefix for the function name:

struct TextMessage {
    // ...
};

void text_message_set(struct TextMessage* message) { /* ... */ }

void text_message_get(struct TextMessage* message) { /* ... */ }

Typedef of simple value types

Typedefs for simple value types (such as int, int64_t, char) are lower snake case. They are postfixed with _t

Examples:

typedef uint32_t thread_id_t;