Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Assigning NULL to a variable (not pointer)

Reply
Thread Tools

Assigning NULL to a variable (not pointer)

 
 
Jim Langston
Guest
Posts: n/a
 
      10-17-2006
"Ron Natalie" <(E-Mail Removed)> wrote in message
news:4534d1bd$0$5894$(E-Mail Removed) ...
> Jim Langston wrote:
>
>>
>> int MyVar = NULL;
>>
>> I would immediatly presume that MyVar is being cast to a pointer
>> somewhere and is not acutally used as an integer. And I would start
>> reading the code with that in mind.
>>

>
> There's no guarantee that a int reinterpret_casted to a pointer yields
> a null pointer value. You get only two guarantees:
>
> 1. A integer constant expression of value zero converts to a null
> pointer.
>
> 2. A pointer value can be converted to a sufficiently large integer
> (if such exists) and back to the original pointer type without
> change.


I agree to that, yet I still see unsigned long ints used as pointers in some
code written for Windows.


 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      10-17-2006
Jim Langston wrote:

>
> I agree to that, yet I still see unsigned long ints used as pointers in some
> code written for Windows.
>
>


Windows has a type for that actually. They call it DWORD_PTR
which took me a while to realize it isn't a poitner to a DWORD
but a integral type that's big enough to hold either a DWORD
or a pointer. Microsoft had to chase down these when they
went to x64 because they were using DWORD (32 bits) to hold
pointers all over the place in the hideous windows message system.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
assigning pointer to NULL Ian Collins C Programming 27 02-10-2008 10:35 PM
Assigning methods to objects, and assigning onreadystatechange to an XMLHttpRequest -- an inconsistency? weston Javascript 1 09-22-2006 09:33 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
if instance variable get initialize after assigning some values or after constructor then when does static variable get initialize Tony Morris Java 3 02-04-2006 08:39 AM
Assigning value to null Steve Caliendo ASP .Net 1 06-08-2004 04:41 PM



Advertisments