Skip to content

Latest commit

 

History

History
41 lines (25 loc) · 1.34 KB

File metadata and controls

41 lines (25 loc) · 1.34 KB

OpenDMI: Coding conventions

Formatting

Spacing and braces

  • Indent using four (4) spaces. Do not use tabs for indentation.

  • Use no space between * and the variable name in pointer expressions (int *foo).

  • Use space between keywords and parentheses; e.g., if (condition).

  • Put the opening brace of a function implementation on the line after the function’s return type, name, and argument list.

Header guards

  • Use #pragma once in addition to include guargs in header files to avoid duplicated includes.

Naming

  • Use snake_case to name a multi-word variable or type.

  • Use UPPER_SNAKE_CASE for, and only for, preprocessor symbols and values of enumeration type.

  • Use typedef to create aliases for all struct types.

  • The names of type aliases should always end in _t.

  • Function pointer type aliases should always end in _fn.

  • Do not alias pointer types with typedef; we keep them explicit.

  • Name boolean variables with a verb phrase including a verb like is_, has_, or want_ so that the intent of the variable is clear in expressions and conditionals.

  • Avoid magic numbers; define meaningful constants. Prefer C language symbols over preprocessor symbols, because the former are visible in a symbolic debugger like gdb.

Common abbreviations

addr

Address

iface

Interface

proto

Protocol