Home

On 2007-08-03 19:11:30 -0400, Andre Kostur <nntpspam@kostur.net> said:

> Gianni Mariani <gi3nospam@mariani.ws> wrote in news:46b3a088$0$31411
> $5a62ac22@per-qv1-newsreader-01.iinet.net.au:
>
>> James Kanze wrote:
>> ...
>>>> Be careful using the "if(p)" syntax; it does an integer
>>>> comparison on the pointer which isn't valid on all platforms.
>>>
>>> No it doesn't. The condition in an if must have type bool.
>>> There is an implicit conversion of pointer to bool, which is
>>> basically the equivalent of "p != NULL". Code like "if (p)" may
>>> be unreadable, and it's not the sort of thing you'd ever see in
>>> well written C++, but it is perfectly legal and well defined.
>>
>> if (p) *IS* readable. There is nothing ambiguous, unclear or not "well
>> written" about it other than it's missing one of the silliest standard
>> macros since the beginning C compared to if (p != NULL).
>
> I disagree. I prefer the explicit test against NULL. (I'd prefer it even
> more if they standardize on a keyword nulptr). I dislike testing implicit
> conversions to bool, so the only time I write "if (p)" is only if p is a
> bool. If it is anything else, I'll write out the full test; "if (p != 0)"
> for example.


--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

previous
next

Re: Move files/directories to Recycle Bin using standard Python libs
Re: Memory layout question
Re: So what exactly is a complex number?
Re: Screen to Memory.....
Re: The Modernization of Emacs: terminology buffer and keybinding
Dzieci Niczyje
Rodzic Po Ludzku
Fundacja Avalon
Pajacyk
Kidprotect