| title |
|---|
C++ notes around tooling |
Add // comment at the end of line to force clang-format to NOT merge
everything into single line. This:
const int status = ...;
if ((status == e1) || (status == e2) || other_error)
{
HandleMe();
}becomes:
const int status = ...;
if ((status == e1) //
|| (status == e2) //
|| other_error)
{
HandleMe();
}- Note clang-format version with
clang-format.exe --version. - Dump some (any?) available style to .clang-format with
clang-format.exe --style=Microsoft --dump-config > .clang-format. - (You may want to force everyone to use same clang-format version).
- (Check ClangFormatStyleOptions reference).
Add header with above info to .clang-format, submit:
# clang-format version 18.1.8
# clang-format.exe --style=Microsoft --dump-config > .clang-format
---
Language: Cpp
# BasedOnStyle: Microsoft
...
// clang-format off
MyHandle(56
, "args"
, "data"
);
// clang-format onSingle file:
clang-format.exe -i --style=file:.clang-format "main.cpp"
Folder:
ls -Path . -Recurse -File -Include *.h,*.cpp `
| % { clang-format.exe -i --style=file:.clang-format $_.FullName }
See /d1reportAllClassLayout – Dumping Object Memory Layout and VC++ 2013 class Layout Change and Wasted Space. For this code:
// main.cpp
struct MyBase
{
virtual ~MyBase() = default;
virtual void MyFoo() {};
int _data = -1;
};
struct MyDerived : MyBase
{
virtual void MyFoo() override {};
float _id = 0.0f;
};Running
cl /d1reportSingleClassLayout[MyDerived]{.mark} main.cpp
will dump:
class MyDerived size(12):
+---
0 | +--- (base class MyBase)
0 | | {vfptr}
4 | | _data
| +---
8 | _id
+---
MyDerived::$vftable@:
| &MyDerived_meta
| 0
0 | &MyDerived::{dtor}
1 | &MyDerived::MyFoo
Note there is also /d1reportAllClassLayout so you don't need to specify class name.