]> git.ipfire.org Git - thirdparty/git.git/blobdiff - Documentation/CodingGuidelines
Merge branch 'jc/codingstyle-compare-with-null'
[thirdparty/git.git] / Documentation / CodingGuidelines
index 390ceece523ed9ec2221563d991f8ec0bf83b461..227f46ae403ea85a1bea17892aa4b038820b5f9b 100644 (file)
@@ -95,10 +95,6 @@ For shell scripts specifically (not exhaustive):
 
  - We use Arithmetic Expansion $(( ... )).
 
- - Inside Arithmetic Expansion, spell shell variables with $ in front
-   of them, as some shells do not grok $((x)) while accepting $(($x))
-   just fine (e.g. dash older than 0.5.4).
-
  - We do not use Process Substitution <(list) or >(list).
 
  - Do not write control structures on a single line with semicolon.
@@ -236,6 +232,18 @@ For C programs:
         while( condition )
                func (bar+1);
 
+ - 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:
+
+       if (!ptr || cnt)
+               BUG("empty array expected");
+
+   and not:
+
+       if (ptr == NULL || cnt != 0);
+               BUG("empty array expected");
+
  - We avoid using braces unnecessarily.  I.e.
 
        if (bla) {