lkml.org 
[lkml]   [2018]   [Mar]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] Documentation/CodingStyle: Add an example for braces
Date
On Wed, 14 Mar 2018, Gary R Hook <gary.hook@amd.com> wrote:
> Add another example of required braces when using a compound statement in
> a loop.
>
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
> Documentation/process/coding-style.rst | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
> index a20b44a40ec4..d98deb62c400 100644
> --- a/Documentation/process/coding-style.rst
> +++ b/Documentation/process/coding-style.rst
> @@ -200,6 +200,15 @@ statement; in the latter case use braces in both branches:
> otherwise();
> }
>
> +Also, use braces when a loop contains more than a single simple statement:

Personally, I'd not limit this to loops.

if (condition) {
if (another_condition)
action();
}

You could argue the existing rule already covers these cases by
excluding selection and iteration statements from the "single statement"
in "Do not unnecessarily use braces where a single statement will do."

BR,
Jani.

> +
> +.. code-block:: c
> +
> + while (condition) {
> + if (test)
> + do_something();
> + }
> +
> 3.1) Spaces
> ***********
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-doc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html

--
Jani Nikula, Intel Open Source Technology Center

\
 
 \ /
  Last update: 2018-03-15 11:25    [W:1.969 / U:0.000 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site