Navigation Menu

Skip to content

Commit

Permalink
doc coding-style: add about NULL in condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Mar 15, 2012
1 parent 57f367a commit 3d65ee6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/source/developer/coding_style.rst
Expand Up @@ -452,3 +452,18 @@ bool型を用いる
boolean is_searching = true;
if (is_searching == false) { ... }

``NULL`` と比較しない
^^^^^^^^^^^^^^^^^^^^^^

``NULL`` かどうかを条件式に使う場合は ``value == NULL`` ではなく ``!value`` というように書く。多くの言語で ``NULL`` に相当する値(たとえばLispの ``nil`` )は偽を表すため、明示的に ``NULL`` と比較しなくても意図は伝わるからである。

よい例:

char *name = NULL;
if (!name) { ... }
悪い例( ``NULL`` と比較している):

char *name = NULL;
if (name == NULL) { ... }

0 comments on commit 3d65ee6

Please sign in to comment.