Skip to content

Commit 73d9f96

Browse files
committed
Merge branch 'jc/codingstyle-compare-with-null'
Doc update. * jc/codingstyle-compare-with-null: CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL
2 parents f9dbe28 + 5c7bb01 commit 73d9f96

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Documentation/CodingGuidelines

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ For C programs:
232232
while( condition )
233233
func (bar+1);
234234

235+
- Do not explicitly compare an integral value with constant 0 or '\0',
236+
or a pointer value with constant NULL. For instance, to validate that
237+
counted array <ptr, cnt> is initialized but has no elements, write:
238+
239+
if (!ptr || cnt)
240+
BUG("empty array expected");
241+
242+
and not:
243+
244+
if (ptr == NULL || cnt != 0);
245+
BUG("empty array expected");
246+
235247
- We avoid using braces unnecessarily. I.e.
236248

237249
if (bla) {

0 commit comments

Comments
 (0)