diff options
author | Junio C Hamano <gitster@pobox.com> | 2024-08-20 22:36:11 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-08-20 23:10:10 +0200 |
commit | 44db6f75cce574a0e410df5be61d40f28ec16f0a (patch) | |
tree | 1f9ba313b922c7e211323fa9d6190df3488f630e /Documentation/CodingGuidelines | |
parent | Prepare for 2.46.1 (diff) | |
download | git-44db6f75cce574a0e410df5be61d40f28ec16f0a.tar.xz git-44db6f75cce574a0e410df5be61d40f28ec16f0a.zip |
CodingGuidelines: spaces around C operators
As we have operated with "write like how your surrounding code is
written" for too long, after a huge code drop from another project,
we'll end up being inconsistent before such an imported code is
cleaned up. We have many uses of cast operator with a space before
its operand, mostly in the reftable code.
Spell the convention out before it spreads to other places.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rw-r--r-- | Documentation/CodingGuidelines | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 52afb2725f..4e6edf3d66 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -293,7 +293,9 @@ For C programs: v12.01, 2022-03-28). - Variables have to be declared at the beginning of the block, before - the first statement (i.e. -Wdeclaration-after-statement). + the first statement (i.e. -Wdeclaration-after-statement). It is + encouraged to have a blank line between the end of the declarations + and the first statement in the block. - NULL pointers shall be written as NULL, not as 0. @@ -313,6 +315,13 @@ For C programs: while( condition ) func (bar+1); + - A binary operator (other than ",") and ternary conditional "?:" + have a space on each side of the operator to separate it from its + operands. E.g. "A + 1", not "A+1". + + - A unary operator (other than "." and "->") have no space between it + and its operand. E.g. "(char *)ptr", not "(char *) ptr". + - Do not explicitly compare an integral value with constant 0 or '\0', or a pointer value with constant NULL. For instance, to validate that counted array <ptr, cnt> is initialized but has no elements, write: |