diff options
author | Mark Whitley <markw@lineo.com> | 2000-07-26 00:30:00 +0400 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2000-07-26 00:30:00 +0400 |
commit | 52681b48dc23bf75609dfdc06933793f21fbc323 (patch) | |
tree | 4f4b9b5d9d11280d27c62aaea202af2eeea78baf | |
parent | fad9c1198aa9486f2df01fe139afa329eb893b58 (diff) |
Added a note in the "Tips and Pointer" section on the correct way to test for
string equivalence with strcmp().
-rw-r--r-- | docs/style-guide.txt | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/style-guide.txt b/docs/style-guide.txt index 28fb1fbfc..d1257b755 100644 --- a/docs/style-guide.txt +++ b/docs/style-guide.txt @@ -175,6 +175,23 @@ The following are simple coding guidelines that should be followed: (Side Note: we might want to use a single file instead of two, food for thought). + - There's a right way and a wrong way to test for sting equivalence with + strcmp: + + The wrong way: + + if (!strcmp(string, "foo")) { + ... + + The right way: + + if (strcmp(string, "foo") == 0){ + ... + + The use of the "equals" (==) operator in the latter example makes it much + more obvious that you are testing for equivalence. The former example with + the "not" (!) operator makes it look like you are testing for an error. + - Do not use old-style function declarations that declare variable types between the parameter list and opening bracket. Example: |