J
junky_fellow
I have a question related to pointer/integer conversion.
After reading various threads on this newsgroup I found that
pointer/integer conversion is not portable and may lead to
undefined results even on the same platform. I was just curious
to know why is it so ? One obvious reason is that size of
pointer variable might not be the same as integer variable.
What could be the other reasons ?
Consider an implementation where pointers and integer variables
are all of *same* size (say 4 bytes).
On such a platform, can the integer/pointer conversion cause
any undefined results ? Why ?
For eg. Consider the following piece of code:
int main (void)
{
int * ptr_i ;
int value = 0x100; /* I want to access location 0x100 in
memory */
ptr_i = value;
}
Assume sizeof(int *) is equal to sizeof(int).
What sort of problems could the "ptr_i = value" may lead to ?
After the conversion of "value" to "ptr_i", is it possible
that "ptr_i" contain altogether a different value ?
After reading various threads on this newsgroup I found that
pointer/integer conversion is not portable and may lead to
undefined results even on the same platform. I was just curious
to know why is it so ? One obvious reason is that size of
pointer variable might not be the same as integer variable.
What could be the other reasons ?
Consider an implementation where pointers and integer variables
are all of *same* size (say 4 bytes).
On such a platform, can the integer/pointer conversion cause
any undefined results ? Why ?
For eg. Consider the following piece of code:
int main (void)
{
int * ptr_i ;
int value = 0x100; /* I want to access location 0x100 in
memory */
ptr_i = value;
}
Assume sizeof(int *) is equal to sizeof(int).
What sort of problems could the "ptr_i = value" may lead to ?
After the conversion of "value" to "ptr_i", is it possible
that "ptr_i" contain altogether a different value ?