In message <[EMAIL PROTECTED]>, "Mike Meyer" writes:
>I'll grant that the change Paul suggested makes it clear - the
>programmer knows when the function is returning an int or not. But
>it's not clear that it achieves his intent. is
>
> char *p;
> if (p = somerandomfunction(with, args)) {
> }
>
>really less readable than:
>
> char *p;
> if ((p = somerandomfunction(with, args)) != NULL) {
> }
Ahh, but here you hit one of my pet-peeves. I hate assignments inside
conditionals. I prefer the above written as:
char *p;
p = somerandomfunction(with, args);
if (p != NULL) {
}
Anyway, if you want it spelled out the way I would want it:
0. No assignments in if()
1. In conditions, pointers should be explicitly compared against NULL:
if (foo == NULL)
or
if (foo != NULL)
2. In conditions, non-interger numeric types should be explicitly compared
to zero
if (float_t == 0.0)
3. Integers need not be explicitly compared to zero:
if (foo & MASK)
not
if ((foo & MASK) != 0)
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
[EMAIL PROTECTED] | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message