Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / October 2004

Tip: Looking for answers? Try searching our database.

default value of a pointer type

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George - 26 Oct 2004 09:45 GMT
Hi!

What is the default value of a pointer type?

Is it "null"? since a pointer type is in particular a reference type

Thanks. George
Mattias Sj?gren - 26 Oct 2004 12:00 GMT
>What is the default value of a pointer type?
>
>Is it "null"?

Zero, or null of you see it from a C# point of view.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

George - 26 Oct 2004 12:09 GMT
Hi Mattias,

Thanks.

> Zero, or null of you see it from a C# point of view.

from the CIL point of view, is it zero?
Brian Tyler - 26 Oct 2004 15:01 GMT
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

> Hi Mattias,
>
[quoted text clipped - 3 lines]
>
> from the CIL point of view, is it zero?
George - 26 Oct 2004 15:11 GMT
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?
Brian Tyler - 26 Oct 2004 15:43 GMT
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?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.