null to delegate cast?
icee
iceelyne at gmail.com
Sun Sep 10 19:32:59 PDT 2006
In http://www.digitalmars.com/d/expression.html, you said
"A null is implicitly converted to a Type delegate() by creating an
anonymous delegate that returns null."
But the truth seems not:
//char[] delegate () dg = null; //cause av
char[] delegate () dg = delegate char[]() {return null;};
try{dg();}catch(Exception e){writefln(e.msg);}
or, if i made any mistakes here?
null
The keyword null represents the null pointer value; technically it is of
type (void *). It can be implicitly cast to any pointer type, including
pointers to functions. The integer 0 cannot be cast to the null pointer.
Nulls are also used for empty arrays.
A null is implicitly converted to a Type delegate() by creating an anonymous
delegate that returns null. To get an actual null value for the delegate,
use one of the following:
const Type delegate() dgnull; // default initializer for delegate is null
...
Type delegate() dg1; // default initializer for delegate is null
Type delegate() dg2 = dgnull;
Type delegate() dg3 = (Type delegate()).init;
Type delegate() dg4 = cast(Type delegate()) null;
Type delegate() dg5 = null; // initializes dg5 to
// delegate Type() { return null; }
More information about the Digitalmars-d-bugs
mailing list