anjali wrote:
Consider the following code:
#include <stdio.h>
int main(void)
{
char buf[100];
unsigned i;
i=(unsigned)buf +100;
printf("%u\n",i);
return 0;
}
Can anybody please tell me that is there is any way to write in the
memory area reserved by the buf array only by using the integer "i" ?
There is no portable way to do this. The conversion
from `char*' (which is what `buf' becomes in most contexts,
including this one) to `unsigned' produces an implementation-
defined result which may not be of any use in addressing
the memory later on. For example, on a machine with 64-bit
pointers and a 32-bit `unsigned' the conversion necessarily
loses data.
The question have some importance for me as I have to use such a
technique for pushing the parameters in a thread's stack using the
setjmp function in the Linux OS.
What you are doing is outside the bounds of the C language.
You are attempting to "look behind the curtain," and what you
find there is an artifact of the C implementation you happen
to be using at the moment. Your question isn't about C, but
about the internals of one implementation of C -- so you need
to find a newsgroup or other source of information specifically
about the system you're interested in.
--
Er*********@sun.com