On Mon, Nov 17, 2014 at 11:18:36PM +0100, FRIGN wrote:
> On Mon, 17 Nov 2014 14:10:49 -0800
> Bobby Powers <bobbypowers_AT_gmail.com> wrote:
>
> > By default I read if (!functioncall()) as 'if the function call
> > failed'. I like the (strcmp(p, q) == 0) idiom because I don't fall
> > into the trap of reading the statement as 'if the string comparison
> > failed'. It is the one case I can think of where I prefer an explicit
> > comparison to zero.
>
> De gustibus non est disputandum.
>
> However, given strcmp is such a special case, I was used to the == 0
> idiom as well.
> However, the more I used the ! the easier it was to read it.
No. The idea is that if you are comparing pointers or functions/variables
that obviously return 0 or 1 (like isspace() or bflag or similar) then you
can use !v and v.
If you are comparing anything else then you should explicitly check
for it. strcmp() has 3 classes of return values < 0, == 0 and > 0.
On a side note here, for a failing syscall or similar, I think the
idea is to check for < 0 rather than == -1. I am not opposed to the
latter except that is already used less frequently in sbase.
Received on Tue Nov 18 2014 - 11:31:50 CET
This archive was generated by hypermail 2.3.0
: Tue Nov 18 2014 - 11:36:13 CET