comparing typedefed type to null
mike
vertex at gmx.at
Fri Mar 2 07:42:10 PST 2007
Am 02.03.2007, 01:40 Uhr, schrieb Rick Mann <rmann-d-lang at latencyzero.com>:
> In writing code against the Mac OS X Carbon API, I often have a need to
> do this:
>
> struct __Foo {};
> typedef Foo* FooRef;
> typedef FooRef BarRef;
>
> {
> BarRef br = ...;
> FooRef fr = ...;
> if (br == null) {} // complain
> if (fr == null) {} ok
>
> GDC 0.22/DMD 1.004 complains about the comparison to br: "Error:
> incompatible types for ((br) == (null)): 'BarRef' and 'void*'
>
> I can avoid it by aliasing BarRef instead of typedefing it, but I have
> the need to allow a BarRef to be passed to FooRef parameters, but not
> the other way around. The typedef gives me that.
You should always use the "is" operator to check for null:
' if (br is null) { ... }
-Mike
--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/
More information about the Digitalmars-d-learn
mailing list