Coding Style

Use this coding guideline to ensure that your development complies with the project’s style and naming conventions.

In general, follow the Linux kernel coding style, with the following exceptions:

  • Add braces to every if and else body, even for single-line code blocks. Use the --ignore BRACES flag to make checkpatch stop complaining.
  • Use hard tab stops. Set the tab width to either 4 or 8 spaces. Train checkpatch to only warn when lines are over 100 characters. In general, break lines at 80 characters where possible. If you are trying to align comments after declarations, use spaces instead of tabs to align them.
  • Use C89-style single line comments, /* */. The C99-style single line comment, //, is not allowed.
  • Use /**  */ for any comments that need to appear in the documentation.

Checking for Conformity Using Checkpatch

The Linux kernel GPL-licensed tool checkpatch is used to check coding style conformity. Checkpatch is available in the scripts directory. To invoke it when committing code, edit your .git/hooks/pre-commit file to contain:

#!/bin/sh

set -e exec

exec git diff --cached | ${ZEPHYR_BASE}/scripts/checkpatch.pl - || true