Breaking Long Lines

Chris Johns chrisj at rtems.org
Mon Nov 9 00:52:21 UTC 2020


On 6/11/20 7:11 pm, Sebastian Huber wrote:
> Hello,
> 
> for breaking long lines we have currently:
> 
> "Should be replaced with
> 
> .. code-block:: c
> 
>   for (
>     initialization = statement;
>     a + really + longish + statement + that + evaluates + to <
>     a + boolean;
>     another + statement++
>   ) {
>     z = a + really + longish + statement + that + needs +
>         two + lines + gets + indented + four + more +
>         spaces + on + the + second + and + subsequent +
>         lines + and + broken + up + at + operators;
>   }
> 
> Note that indentations should add 2 nesting levels (4 space characters, not tabs)."
> 
> Do we really need two indent levels for breaking long lines in block statements?
> I would just say that the continuation of a broken line is indented by one
> level. The example would look like this (please note the change in the for loop
> "a + boolean"):
> 
> .. code-block:: c
> 
>   for (
>     initialization = statement;
>     a + really + longish + statement + that + evaluates + to <
>       a + boolean;
>     another + statement++
>   ) {
>     z = a + really + longish + statement + that + needs +
>       two + lines + gets + indented + four + more +
>       spaces + on + the + second + and + subsequent +
>       lines + and + broken + up + at + operators;

I sometimes add parentheses to aid indenting:

  z = (a + really + longish + stat
             ....
       lines + and + broken + up + at + operators);

Emacs automatically indents to the opening `(`. This is mentioned in the GNU
coding standard. We however have this statement in our standard ...

 Avoid excess parentheses. Learn the operator precedence. rules.

Chris

>   }
> 


More information about the devel mailing list