Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

C/C++ Style Proposal #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions styles/C.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## C and C++

### Code Format and Style

Generally, the source code should obey the style documented
by [the configuration for clang-format](c-clang-format.yml).
It's aimed to follow [NetBSD KNF](http://cvsweb.netbsd.org/bsdweb.cgi/src/share/misc/style?rev=HEAD&content-type=text/x-cvsweb-markup) loosely.

However, there are a few exceptions.

* We don't change the style of the imported code.
We try to keep local changes minimum.
Ideally, no local changes.

* Notably, code imported from NuttX should obeys
[NuttX Coding Standard](https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard).

### Tools

The `clang-format` tool from LLVM 13 with the above mentioned configuration
can be used to check and/or fix the style.

#### NuttX Coding Standard

The [nxstyle](https://github.com/apache/incubator-nuttx/blob/master/tools/nxstyle.c)
tool can be used to check the style.
60 changes: 60 additions & 0 deletions styles/c-clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 8
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
PointerAlignment: Right
ColumnLimit: 79
TabWidth: 8
UseTab: ForContinuationAndIndentation
AlignConsecutiveMacros: true
AlwaysBreakAfterReturnType: TopLevelDefinitions
ForEachMacros: ["TAILQ_FOREACH", "TAILQ_FOREACH_SAFE"]
BreakBeforeBraces: Custom
BraceWrapping:
AfterControlStatement: Never
AfterCaseLabel: false
AfterEnum: false
AfterFunction: true
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeElse: false
BeforeWhile: false
SplitEmptyFunction: true
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SortIncludes: true
IndentCaseBlocks: true
IndentCaseLabels: false
IncludeBlocks: Regroup
# Disable file-to-main-include by specifying a regex which never match
IncludeIsMainRegex: '/INEXISTENT$'
IncludeCategories:
- Regex: '<nuttx/.*'
Priority: 1
- Regex: '<sys/.*'
Priority: 2
# 3rd party libraries
- Regex: '<mbedtls/.*'
Priority: 4
- Regex: '<mqtt\.h>'
Priority: 4
- Regex: '<wasm_export.h>'
Priority: 4
# private fork of 3rd party libraries
- Regex: '"webclient/.*'
Priority: 5
- Regex: '"netlib/.*'
Priority: 5
- Regex: '"azure/.*'
Priority: 5
# system headers
- Regex: '<.*'
Priority: 3
- Regex: '".*'
Priority: 6
- Regex: '.*'
Priority: 7