Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > pointer to inte...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 13 Topic 26086 of 26198
Post > Topic >>

pointer to integer to pointer conversions

by lithiumcat@[EMAIL PROTECTED] May 6, 2008 at 05:05 AM

Hi,

I bothered you a while back about storing integer values in void*. Now
in a completely unrelated context, I'm trying to store pointer values
in an integer type.

So the basic question is, is it possible to convert a pointer into an
integer, and then later (but on the same execution environment, ie the
program has not exited, thus it's the same architecture, same
compiler, same binary representations and so on) retrieve from the
integer the "same" pointer (that is, a pointer that points to the same
object and that would compare equal to the original pointer if it was
kept somewhere)?

On the document I found, named "ISO/IEC 9899:TC3", I have found on
paragraph 6.3.2.3 that pointers can be converted into integers and
vice versa, provided the integer type is large enough, the result
being implementation-defined. Does it mean the standard does not
guarantee that converting to an integer and back to a pointer yeilds
the same pointer? Or is it written somewhere else?

I gather that this document is about C99, is the answer different in
C89?

And supposing that conversion might work, should I make sure the
original pointer and the retrieved pointer have exactly the same type,
or can it work with one them being of a given type and the other one
being a void* later converted into a pointer of the correct type?

In any case it works, is there a portable way to know what integer
types are large enough to hold a pointer value?

In case it matters, my situation is that I want, for debug purposes,
to output the "value" of a pointer to the user (me), and then read
that value back from the user. The most natural way to make a user
handle pointers was to print and read it as an integer. Of course I
don't really need portability in that case, but I have the feeling
that it might be useful knowledge later on. Or maybe I'm only
overemphasizing portability the same way too many people overemphasize
performance.




 13 Posts in Topic:
pointer to integer to pointer conversions
lithiumcat@[EMAIL PROTECT  2008-05-06 05:05:39 
Re: pointer to integer to pointer conversions
vippstar@[EMAIL PROTECTED  2008-05-06 05:34:20 
Re: pointer to integer to pointer conversions
Eric Sosman <esosman@[  2008-05-06 08:37:09 
Re: pointer to integer to pointer conversions
rlb@[EMAIL PROTECTED] (R  2008-05-07 08:17:12 
Re: pointer to integer to pointer conversions
"Stephen Sprunk"  2008-05-07 16:37:01 
Re: pointer to integer to pointer conversions
Keith Thompson <kst-u@  2008-05-07 15:45:19 
Re: pointer to integer to pointer conversions
lithiumcat@[EMAIL PROTECT  2008-05-06 08:33:00 
Re: pointer to integer to pointer conversions
Keith Thompson <kst-u@  2008-05-06 12:46:11 
Re: pointer to integer to pointer conversions
Flash Gordon <spam@[EM  2008-05-06 21:42:38 
Re: pointer to integer to pointer conversions
vippstar@[EMAIL PROTECTED  2008-05-07 06:54:46 
Re: pointer to integer to pointer conversions
Peter Nilsson <airia@[  2008-05-07 15:30:26 
Re: pointer to integer to pointer conversions
rlb@[EMAIL PROTECTED] (R  2008-05-08 12:52:49 
Re: pointer to integer to pointer conversions
Peter Nilsson <airia@[  2008-05-07 15:44:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 6:51:48 CDT 2008.