[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
indentation uncertainty
From: |
Alexandre Oliva |
Subject: |
indentation uncertainty |
Date: |
Wed, 07 Feb 2018 02:26:10 -0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) |
[please copy me explicitly in responses; I'm not (yet?) subscribed to
the list]
Hi, there,
Some uncertainly has come up during GCC patch review. I'd appreciate
some clarification on the indentation rules in the GNU coding
standards. The current document states:
Insert extra parentheses so that Emacs will indent the code properly.
For example, the following indentation looks nice if you do it by
hand,
v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
+ rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
but Emacs would alter it. Adding a set of parentheses produces
something that looks equally nice, and which Emacs will preserve:
v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
+ rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
It's not clear whether the first code snippet is incorrectly indented,
or whether the only problem with it is that mechanical reindent will
then make it improper. Mechanical reindent would turn it into:
v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
+ rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
which is improper, presumably because '=' and '+' are at the same
indentation level, in spite of being operators with different
precedence, contradicting the earlier rule:
Try to avoid having two operators of different precedence at the same
level of indentation.
Now, what if, instead of as assignment, we had a return statement,
without an '=' operator of higher precedence?
Would any of the following 4 forms be deemed improper in GNU code?
return rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
+ rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
return (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
+ rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
return rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
+ rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
return
(rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
+ rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
If any of them are, the addition, to the standard document, of the
snippet and rationale would be appreciated.
Thanks in advance,
--
Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/ FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer
- indentation uncertainty,
Alexandre Oliva <=