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>
Junio C Hamano committed
Aug 20, 2024 at 13:36 UTC
44db6f75cce574a0e410df5be61d40f28ec16f0a
1 file changed
+10
-1
Documentation/CodingGuidelines
+10
-1
@@ -293,7 +293,9 @@ For C programs:
293
v12.01, 2022-03-28).
294
295
- Variables have to be declared at the beginning of the block, before
296
- the first statement (i.e. -Wdeclaration-after-statement).
296
+ the first statement (i.e. -Wdeclaration-after-statement). It is
297
+ encouraged to have a blank line between the end of the declarations
298
+ and the first statement in the block.
299
300
- NULL pointers shall be written as NULL, not as 0.
301
@@ -313,6 +315,13 @@ For C programs:
315
while( condition )
316
func (bar+1);
317
318
+ - A binary operator (other than ",") and ternary conditional "?:"
319
+ have a space on each side of the operator to separate it from its
320
+ operands. E.g. "A + 1", not "A+1".
321
+
322
+ - A unary operator (other than "." and "->") have no space between it
323
+ and its operand. E.g. "(char *)ptr", not "(char *) ptr".
324
+
325
- Do not explicitly compare an integral value with constant 0 or '\0',
326
or a pointer value with constant NULL. For instance, to validate that
327
counted array <ptr, cnt> is initialized but has no elements, write: