Re: addresses and integers
From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 08/31/04
- Next message: Dan Pop: "Re: addresses and integers"
- Previous message: pete: "Re: Array size limits"
- In reply to: junky_fellow: "Re: addresses and integers"
- Next in thread: Jack Klein: "Re: addresses and integers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 Aug 2004 12:28:38 GMT
In <8c7d4a6e.0408300702.368efb7c@posting.google.com> junky_fellow@yahoo.co.in (junky_fellow) writes:
>why the conversion of a pointer type variable to integer invalid ?
The standard says that it's valid (with one exception) and that the
result is implementation-defined.
>what's the reason behind that ?
It may be possible (AS/400 springs to mind) that no integer type is
wide enough to hold the result of the conversion. This is the exception
mentioned above.
As for the implementation-defined result, there are architectures, like
the 8086, where the pointer value is not the same as the address pointed
to and most addresses can have 4096 different representations as pointer
values.
>i always had in my mind that pointer variable contains some address,
>which is some integer value ?
In some cases, see above, it may be more than one integer value. The
actual address is computed by the CPU itself, from these numbers.
>and i can add/subtract after typecasting the pointer variable to int.
You can do that, but the result need not have the desired/expected
meaning. You have to understand how the conversion works on a given
platform (the implementation must document it) in order to do this kind
of things in a meaningful way. Which means that the code cannot be
expect to work as intended on another implementation.
Dan
-- Dan Pop DESY Zeuthen, RZ group Email: Dan.Pop@ifh.de
- Next message: Dan Pop: "Re: addresses and integers"
- Previous message: pete: "Re: Array size limits"
- In reply to: junky_fellow: "Re: addresses and integers"
- Next in thread: Jack Klein: "Re: addresses and integers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|