The Is Operator

Janice Caron caron800 at googlemail.com
Thu Oct 4 11:08:21 PDT 2007


On 10/4/07, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
> Anders F Björklund wrote:
> > Bill Baxter wrote:
> >
> >> More annoying to me is that !in doesn't work.
> >
> > What's the logical negation of a pointer, anyway ?
>
> bool negated_pointer = !some_ptr;
>
> Seems pretty clear to me.

Technically speaking, what you've done there is implicitly cast your
pointer to bool and _then_ logically negated it. Mathematically
speaking, if -(-x) does not equal x then you can't call it a negation.
It has to be self-inverse. Logical not has this property when applied
to bools !(!x)== x.

I think this is the point that Anders was making, with some good humor
thrown in. You cannot take the logical not of a pointer. You have to
cast it to bool first.

Of course this is no problem. I'm just being mentioning this for the
hell of it :-)




More information about the Digitalmars-d mailing list