pratap wrote:
consider
int p=10;
int *q=&p;
now my question is how does the compiler (or any type of mechanism)
bind q and p .i.e. memory location of a variable p is bound in a
variable q.
The address of the variable `p` is computed and stored into `q`,
much as in `int x = 10 - 1;` the value of the expression `10 - 1`
is computed (very likely at compile time, in this case) and stored
into `x`.
How does this memory mapping take place.
It isn't what's usually called "memory mapping".
Is there any specific hardware mechanism that helps this mapping.
Typically the ability to do addition.
No, really. If the code you write above occurs in a function,
so that `p` is an auto variable, a common [1] implementation is
to have a register pointing to a stack frame and to have `p`
stored at some offset [2] in that frame, so that the address of `p`
is value-of-frame-pointer-plus-offset. Then the initialisation
of `q` will be `add the frame pointer and the offset and store
the result in q`.
[1] But not universal, and not required by the Standard.
[2] Which could be positive or negative; It Depends.
--
Chris "an example, not a definition" Dollin
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England