Paul Vixie <paul@redbarn.org> writes:
Ken Hornstein wrote:
pointers aren't booleans. in BSD style as used in BIND, this would be:
while ((pp = strchr(pp, '\'')) != NULL && buflen > 3) {
Forgive my stupidity ... but this is just a matter of style, correct?
the same underlying machine code will be generated.
Yeah, it's legal C ...
i would rather give the compiler an extra chance to yell at me. pointers
aren't booleans, in spite of C's ability to treat them that way.
Exactly --- there's a lot of distance between legal C and advisable C.
In this example, for instance, the comparison to NULL makes it clearer
that you did not mean to write
while ((pp == strchr (pp, '\'')) && buflen > 3) {
Your compiler may or may not whine about the shorter coding, depending
on which compiler it is and how high you've cranked its warning options.
But there are a lot of static analysis tools that will whine about it
in any case, and usually that stylistic advice is worth taking. C in
the raw is a bear trap waiting to take your foot off --- anything you
can do to make mistakes more obvious is worth doing.
regards, tom lane
--
Nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers