On Saturday 17 September 2005 08:48, Jerry Feldman wrote:
On Fri, 16 Sep 2005 20:04:29 +0200
Anders Johansson <andjoh@rydsbo.net> wrote:
But I wouldn't include x++ in that definition
The pre-increment/post-increment (and decrement) operators are not fancy code in C, they are an integral part of the language, but they are often misused.
I also do not consider this fancy code: int c; while( (c = getchar()) != EOF) { ... }
Note that I generally try to compare vs. NULL or 0, for example: 'if (p == NULL)'
Ouch. I've had to fix the typo'd version for this too many times: if ( p = NULL ) Syntactically permitted, but definitely not what is intended. If you have warnings turned off this is an invisible error until you run your program and it crashes. If you must do extra typing try this instead: if ( NULL == p ) The typo for this is an invalid assignment and will result in an error, not a warning at compile time.
rather than 'if (!p)' Both are correct in C, but the second is less readable.
I find this second version perfectly understandable, but I've been doing C for about 20 years.