% ClangFormat All The Things % Andrew Seidl % 27 February 2015
- C/C++/ObjC source code formatter
- like astyle, autopep8, go-fmt
- Part of the Clang/LLVM project
- note: Apple doesn't include it with Xcode
- we have all seen some pretty horrible looking code
- w/o shared editor settings, each dev is responsible for config'ing editor
- mitigate flamewars
- BDFL sets repo standard, dissenters use git hooks
struct ChThreadConstructionInfo
{
ChThreadConstructionInfo(char* uniqueName,
int numThreads=1,
int threadStackSize=65535
)
:m_uniqueName(uniqueName),
m_numThreads(numThreads),
m_threadStackSize(threadStackSize)
{
}
char* m_uniqueName;
int m_numThreads;
int m_threadStackSize;
};
struct ChThreadConstructionInfo {
ChThreadConstructionInfo(char *uniqueName,
int numThreads = 1,
int threadStackSize = 65535)
: m_uniqueName(uniqueName),
m_numThreads(numThreads),
m_threadStackSize(threadStackSize) {}
char *m_uniqueName;
int m_numThreads;
int m_threadStackSize;
};
- style specified in
.clang-format
file in top source dir- builtins: LLVM, Google, Chromium, Mozilla, WebKit
- can
BasedOnStyle
, then override specifics
- can be run from command line or inside editor
BasedOnStyle: Chromium
# Longer lines requested by @hmazhar
ColumnLimit: 120
- Eclipse: https://github.com/wangzw/cppstyle
- Emacs: http://clang.llvm.org/docs/ClangFormat.html
- SublimeText: https://github.com/rosshemsley/SublimeClangFormat
- Vim: https://github.com/rhysd/vim-clang-format
- Visual Studio: http://llvm.org/builds/
- Xcode: https://github.com/travisjeffery/ClangFormat-Xcode
-
ClangFormat: http://clang.llvm.org/docs/ClangFormat.html
-
Style options: http://clang.llvm.org/docs/ClangFormatStyleOptions.html
-
.clang-format builder: http://clangformat.com/
-
Style comparison: http://git.io/xtW5
-
Blog post: forthcoming, will issue PR when ready
find . \( -regex '.*\.\(cpp\|cu\|h\)' ! -ipath 'thirdparty' \) -exec clang-format -i '{}' \;