Tracing an address

C

Carlos Martinez

Hi all:

I want to know how can I trace an address.

I don't need the conversion from an integral type to string. Suppose I
have an "asString" function that do that conversion.

My main problem is that code must compile for 2 compilers and 2
Operating Systems. I cannot assume the size of pointers to have 4,
8, ... bytes.

Does standard guarantee a pointer is convertible to a concrete
integral type (for example, unsigned int) ?
If it does, i suppose I can cast to that integral type, but if it
doesn't how can I determine the apropiate type ? Remember 2 different
environments can have 2 different sizes for pointers (I think).

Thanks in advance
 
J

Jack Klein

Hi all:

I want to know how can I trace an address.

What do you mean by "trace"?
I don't need the conversion from an integral type to string. Suppose I
have an "asString" function that do that conversion.

What do integral types have to do with it?
My main problem is that code must compile for 2 compilers and 2
Operating Systems. I cannot assume the size of pointers to have 4,
8, ... bytes.

That doesn't make any difference. If this is a pointer to a complete
or incomplete object type, and that includes pointer to void, you can
store it in a pointer to void.

some_type pointer p = &some_type_object;
void *vp = p;
Does standard guarantee a pointer is convertible to a concrete
integral type (for example, unsigned int) ?

No, the standard does not guarantee that an implementation even has an
integer type wide enough to store the value of a pointer.
If it does, i suppose I can cast to that integral type, but if it
doesn't how can I determine the apropiate type ? Remember 2 different
environments can have 2 different sizes for pointers (I think).

Don't try to do anything at all with integral types. Store the
address in a pointer to void. You can convert a pointer to void to a
text representation with the standard *printf functions using a "%p"
conversion specifier, and C++ stream insertion operators (<<) have an
overload for pointer to void as well.

And if you use a pointer to void to hold the address, it will always
and automatically be the right size on every platform, no matter how
many bits or bytes there are in that platform's implementation of a
void pointer.
Thanks in advance

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top