On Tuesday, 24 August 2010, at 14:38:17 (+1000), David Seikel wrote: > 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.
This is specifically for cases where a boolean value (i.e., Eina_Bool, which is by definition either 0 or !0) is either being assigned to a variable or passed to a function. if (ptr) is still used, but boolvar = (a != NULL) becomes boolvar = !!a. > 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. It's not the NULL value that matters here, but rather the "true" value. !0 may or may not be 1 (~0 is also used). > 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. I find "if (ptr)" and "if (!ptr)" perfectly readable because my brain recognizes "if pointer" and "if not pointer" semantics. BTW, after further discussions with raster, it turns out we actually agree for the most part on the usage of !!. It just happens that the coccinelle script misinterpreted some of my stuff and was too overzealous. I don't mind "b = !!a" but I do mind "ASSERT(!!a)" which coccinelle mistakes for a function. I think this was all one big misunderstanding. :( Michael -- Michael Jennings (a.k.a. KainX) http://www.kainx.org/ <m...@kainx.org> Linux Server/Cluster Admin, LBL.gov Author, Eterm (www.eterm.org) ----------------------------------------------------------------------- "Feel your breath on my shoulder, and I know we couldn't get any closer. I don't want to act tough; I just want to fall in love as we move into the night." -- Peter Cetera and Crystal Bernard, "(I Wanna Take) Forever Tonight" ------------------------------------------------------------------------------ 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