On 2007-07-02 12:50, atif wrote:
Hi
It is well known that Pointer just holds address. But how the machine
came to know that the pointer is holding an address of an Integer so i
will read just 4 bytes and in case of Long 8 bytes. Is it the machine
which decides or compiler does something in the back end ?
Hope i will get some good response
I think this will answer your question: the machine does not know
anything, to the computer the memory is just a long array of bytes. So
given a number of bytes at a specified address what it is depends on how
you interpret it, it might be an integer, an address, a float or a short
string (char array), it's up to the compiler to generate code that
interprets the data correctly.
So lets say you have some bytes somewhere that represents an address to
an integer, then the compiler will have to generate code so that when
you access that memory you read in 4 bytes and treats it as an integer,
if it was a long instead the compiler will generate code which reads 8
bytes and treats it like a long.
--
Erik Wikström