doc: Improvements to coding-style.rst
This commit is contained in:
@@ -97,8 +97,7 @@ Disable formatting in specific files or lines
|
||||
=============================================
|
||||
|
||||
To disable formatting in specific lines, surround them with the following
|
||||
C++ comments [example adopted from
|
||||
`official clang-format documentation <https://clang.llvm.org/docs/ClangFormat.html>`_]:
|
||||
C++ comments:
|
||||
|
||||
.. sourcecode:: cpp
|
||||
|
||||
@@ -917,17 +916,21 @@ to print the numeric value of any variable, such as:
|
||||
|
||||
Avoid unnecessary casts if minor changes to variable declarations can solve
|
||||
the issue. In the following example, ``x`` can be declared as ``float`` instead of
|
||||
``int`` to avoid the cast:
|
||||
``int`` to avoid the cast, or write numbers in decimal format:
|
||||
|
||||
.. sourcecode:: cpp
|
||||
|
||||
// Do not declare x as int, to avoid casting it to float
|
||||
int x = 3;
|
||||
return 1 / static_cast<float>(x);
|
||||
float y = 1 / static_cast<float>(x);
|
||||
|
||||
// Prefer to declare x as float
|
||||
float x = 3.0;
|
||||
return 1 / x;
|
||||
float y = 1 / x;
|
||||
|
||||
// Or use 1.0 instead of just 1
|
||||
int x = 3;
|
||||
float y = 1.0 / x;
|
||||
|
||||
Namespaces
|
||||
==========
|
||||
@@ -1087,7 +1090,7 @@ can be rewritten as:
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
return n;
|
||||
return false;
|
||||
}
|
||||
|
||||
n += 3;
|
||||
|
||||
Reference in New Issue
Block a user