Re: Is an unsigned integer big enough to store a void *?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Under Win32, any type of int is the same size as a pointer. I believe that
is also the case under Win64 as well.

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm

"Tony Young" <jdt_young@xxxxxxxxx> wrote in message
news:ueVGFCfAGHA.3984@xxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> If I use an unsigned integer to store a void pointer, is the unsigned
> integer big enough to store the void pointer? That is, is it possible for
> some cases that truncation or information loss is possible?
>
> void* p;
> ....
> unsigned int d = (unsigned int) p;
> ASSERT(d == p);
>
> The reason I ask is that I need to pass a void * to a library function
> that takes an unsigned integer. Later the function returns it back to me.
> I wonder if the two values (in and out) will be exactly the same.
>
> Please advise. Thanks.
>
> Tony


.



Relevant Pages

  • Re: Passing execution to a memory address
    ... forbidden initialization of function pointer with void pointer ... int add1 ...
    (comp.lang.c)
  • Re: Is an unsigned integer big enough to store a void *?
    ... Although it has been common practice to use int and pointers interchangeably, it is a bad programming practice. ... No assumptions should ever be made about the size of a pointer, and no assumptions should be made that integer arithmetic applied to a pointer will be valid. ... If I use an unsigned integer to store a void pointer, is the unsigned integer big enough to store the void pointer? ...
    (microsoft.public.vc.mfc)
  • Re: operator precedence
    ... > - typecast the void pointer into a type pointer ... But since ++ has precedence over the type cast ... I don't see why the result of (int *) wouldn't be an l-value. ...
    (comp.std.c)
  • Re: Definition of NULL
    ... > that yields a null pointer when evaluated. ... >>I've read a NULL pointer is zero (or zero typecast as a void pointer), ... (int *)0. ...
    (comp.lang.c)
  • Re: working with addresses
    ... > remember that casting to int can involve a loss of information - perhaps ... > pointer on a system with 16-bit ints. ... I am only trying to demonstrate that you don't need to use a void pointer, ... I don't know much about that function itoa. ...
    (alt.comp.lang.learn.c-cpp)