diff options
author | Mark Whitley <markw@lineo.com> | 2000-07-25 20:30:00 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2000-07-25 20:30:00 +0000 |
commit | 52681b48dc23bf75609dfdc06933793f21fbc323 (patch) | |
tree | 4f4b9b5d9d11280d27c62aaea202af2eeea78baf | |
parent | fad9c1198aa9486f2df01fe139afa329eb893b58 (diff) | |
download | busybox-w32-52681b48dc23bf75609dfdc06933793f21fbc323.tar.gz busybox-w32-52681b48dc23bf75609dfdc06933793f21fbc323.tar.bz2 busybox-w32-52681b48dc23bf75609dfdc06933793f21fbc323.zip |
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: | |||
175 | (Side Note: we might want to use a single file instead of two, food for | 175 | (Side Note: we might want to use a single file instead of two, food for |
176 | thought). | 176 | thought). |
177 | 177 | ||
178 | - There's a right way and a wrong way to test for sting equivalence with | ||
179 | strcmp: | ||
180 | |||
181 | The wrong way: | ||
182 | |||
183 | if (!strcmp(string, "foo")) { | ||
184 | ... | ||
185 | |||
186 | The right way: | ||
187 | |||
188 | if (strcmp(string, "foo") == 0){ | ||
189 | ... | ||
190 | |||
191 | The use of the "equals" (==) operator in the latter example makes it much | ||
192 | more obvious that you are testing for equivalence. The former example with | ||
193 | the "not" (!) operator makes it look like you are testing for an error. | ||
194 | |||
178 | - Do not use old-style function declarations that declare variable types | 195 | - Do not use old-style function declarations that declare variable types |
179 | between the parameter list and opening bracket. Example: | 196 | between the parameter list and opening bracket. Example: |
180 | 197 | ||