Zero. Only object references are assigned null.
For example:
static unsafe void Main(string[] args)
{
Int32* x = null;
Object y = null;
}
results in
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 6 (0x6)
.maxstack 1
.locals ([0] int32* x,
[1] object y)
IL_0000: ldc.i4.0
IL_0001: conv.u
IL_0002: stloc.0
IL_0003: ldnull
IL_0004: stloc.1
IL_0005: ret
} // end of method Class1::Main
Thank you Brian! It's clear now.
George
> Zero. Only object references are assigned null.
>
[quoted text clipped - 30 lines]
> >
> > from the CIL point of view, is it zero?
Actually, now that I have written this, I am confused. My understading is
that ldnull has the very nice property of not actually specifying the size
of the "null" to load into the location. Very handy since a reference size
is dependent on the platform (32 vs. 64 bit).
However, a pointer is itself a reference and therefore it would seem that
for the IL to be portable to 64-bit systems, they should be initialized with
ldnull also. This IL was generated with a 1.1 C# compiler, so I don't know
what the 2.0 system does - need to try that next. Granted pointers are
"unsafe", but that isn't the same as "unportable".
Ideas?
> Zero. Only object references are assigned null.
>
[quoted text clipped - 30 lines]
> >
> > from the CIL point of view, is it zero?
Brian Tyler - 26 Oct 2004 16:03 GMT
Okay, my bad. The conv.u is not conv.u4 which is what my brain was seeing,
thus the Int32(0) is converted to a native unsigned int(0).
> Actually, now that I have written this, I am confused. My understading is
> that ldnull has the very nice property of not actually specifying the size
[quoted text clipped - 43 lines]
> > >
> > > from the CIL point of view, is it zero?