On Mon, 23 Aug 2010 20:59:54 -0700 Michael Jennings <m...@kainx.org> wrote:
> On Tuesday, 24 August 2010, at 13:32:06 (+1000), > David Seikel wrote: > > > I'm going to agree that !! is unreadable. Um, does that mean > > negate the negation, hence do nothing, or is their an obscure !! > > operator I have somehow missed in my decades of C programming? > > > > Don't think I have ever seen it before, so would not count is as > > "well known C practice". No doubt for the same reason that double > > negatives are discouraged in English. Not being equal to NULL says > > something, negating the negation is just noise. > > Double negation insures that whatever the compiler's default boolean > value is (sometimes 1, sometimes -1, but theoretically could be > whatever non-zero value it wants, so long as it's consistent) gets > assigned/tested. The double negation insures that any true value gets > negated to false then negated again to the compiler's inate true > value. Um, so it's just a cast to boolean really? Though still it's not the same thing as checking for equality with NULL. In the case of pointers, it's the equivalence or lack of equivalence with NULL that is the important thing. NULL pointers meaning "this pointer does not currently point to anything". We don't really care if the pointer, when cast to a proper boolean value, is true or false, that is completely unrelated to it's identity as a pointer. It may actually work, but it's not what we are interested in. We want to know if the pointer points to something. In C, that means if it is NULL. I understand that on some obscure platforms that we likely don't care about, NULL is not zero, so !! might not actually be portable for pointer NULL testing. Yes, I'm fully aware that far to often I just do "if (pointer)" or "if (!pointer)". I don't see "if (!!pointer)" as being any more readable or correct than "if (pointer)", while grudgingly admitting that "if (NULL != pointer)" is likely more correct. It says what is meant, and the boolean operator produces a boolean result to be used by the boolean statement, no odd casting mishaps possible on obscure platforms. -- A big old stinking pile of genius that no one wants coz there are too many silver coated monkeys in the world.
signature.asc
Description: PGP signature
------------------------------------------------------------------------------ Sell apps to millions through the Intel(R) Atom(Tm) Developer Program Be part of this innovative community and reach millions of netbook users worldwide. Take advantage of special opportunities to increase revenue and speed time-to-market. Join now, and jumpstart your future. http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel