Skip to content

Commit 3fceb1e

Browse files
author
Pavel Kovalenko
committed
Update coding conventions.
1 parent 1fd6ffc commit 3fceb1e

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

doc/procedures/cpp_code.txt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ if the case is one line, then one space after ':':
114114
BAD
115115
switch (vendor)
116116
{
117-
case Vendor::Intel:
117+
case Vendor::Intel :
118118
...
119-
case Vendor::AMD:
119+
case Vendor::AMD :
120120
...
121121
}
122122
GOOD
@@ -348,6 +348,18 @@ not before.
348348
i--;
349349
j++;
350350

351+
Put one space before and after comparison operators:
352+
BAD
353+
if (i==0)
354+
return;
355+
if (j>0)
356+
i = 1;
357+
GOOD
358+
if (i == 0)
359+
return;
360+
if (j > 0)
361+
i = 1;
362+
351363
Don't increment, set or change value of variable inside a function call:
352364
BAD
353365
CalcXY(i++, 2);
@@ -451,12 +463,12 @@ comparing, if they return true or false.
451463
if (cl)
452464
Disconnect(cl);
453465

454-
When allocating a structure on stack, use = {0} unstead of memset:
466+
When allocating a structure on stack, use zero initializer unstead of memset:
455467
BAD
456468
ShaderParams params;
457469
memset(&params, sizeof(params), 0);
458470
GOOD
459-
ShaderParams params = {0};
471+
ShaderParams params = {};
460472

461473
When possible, prefer inline functions to macros:
462474
BAD
@@ -465,7 +477,7 @@ When possible, prefer inline functions to macros:
465477
template <typename T>
466478
T RadiansToDegrees(T angle)
467479
{
468-
return angle * 180 / PI;
480+
return angle*180/PI;
469481
}
470482

471483
Macro names should normally be all upper case, with normal spacing as rest of
@@ -787,11 +799,11 @@ Trivial + - * / expressions should not have spaces around them:
787799
GOOD
788800
Foo((a+b)/(1000*1000));
789801
BAD
790-
Foo((Min(aMin, bMin)+Max(aMax, bMax))*(width*Pow(a, p))/(1000*1000));
802+
Foo((Min(aMin, bMin)+Max(aMax, bMax))*(width+Pow(a, p))/(1000*1000));
791803
GOOD
792-
Foo((Min(aMin, bMin)+Max(aMax, bMax)) * (width*Pow(a, p)) / (1000*1000));
804+
Foo((Min(aMin, bMin)+Max(aMax, bMax)) * (width+Pow(a, p)) / (1000*1000));
793805

794-
Dont put empty lines between code inside functions. If you want to separate
806+
Don't put empty lines between code inside functions. If you want to separate
795807
code fragments, put a comment line.
796808
BAD
797809
for (auto& item : items)

0 commit comments

Comments
 (0)