TODO: Expand beyond naming and formatting
#pragma once
or header guards..cpp
/.mm
and .c
/.m
should have extension .h
.cpp
/.mm
only should have extension .hpp
*.c
, *.cpp
, *.m
, *.mm
). Use fully qualified names for definitions.extern "C"
blocks inside implementation files.namespace kotlin
namespace kotlin
in a nested namespace [module_name]
.h
/.hpp
into a nested namespace internal
(e.g. implementation details of module mm
go into namespace kotlin { namespace mm { namespace internal { ... } } }
).cpp
/.mm
into a global anonymous namespace
extern "C"
declarations emulate namespaces with Kotlin_[module_name]_
prefixes.kotlin::MoveOnly
kotlin::Pinned
PascalCase
camelCase
camelCase
kPascalCase
(with prefix k
)camelCase
PascalCase
camelCase
. Private member fields should add _
suffix: camelCase_
camelCase
SCREAMING_SNAKE_CASE
snake_case
enum
and enum class
members should use kPascalCase
If API is designed to mimic C++ stdlib (e.g. stubbing <atomic>
for platforms that do not support it), its allowed to follow stdlib naming conventions.
For automated formatting you can use config for CLion or clang-format
(see config at the repo‘s root). Note, that CLion uses clang-format
by default; this can be turned off if you prefer to use rules from CLionFormat.xml
. Since 1.8.20 there’s also a :kotlin-native:clangFormat
task that will effectively run git-clang-format -f $(git merge-base origin/master HEAD) -- kotlin-native/
. The task accepts optional arguments --parent
to specify base branch other than origin/master
, and --interactive
to run the tool with -p
flag and interactively accept or reject formatted patches.
Formatting rules are designed to closely mirror Kotlin rules.
*
and &
should be placed on a type instead of a variable*
at all.template
and <