--- In [email protected], "John Matthews" <[EMAIL PROTECTED]> wrote:
>
> --- In [email protected], "raj_duttaphookan"
> <raj_duttaphookan@> wrote:
> >
> > --- In [email protected], "John Matthews" <jm5678@> wrote:
> > >
> > > --- In [email protected], "raj_duttaphookan"
> > > <raj_duttaphookan@> wrote:
> > > >
> > > > Why can't we simply 
> > > > define it as a pointer. It shall anyway hold the memory address 
> > and 
> > > > later on while dereferencing it, it shall automatically 
> > dereference it 
> > > > depending on whether the memory address it contained was that of 
> > an 
> > > > int or a float or a char etc.
> > > 
> > > But when dereferencing, how would the compiler know what was 
> > stored in
> > > the memory? It can't just use the destination type. For example:
> > > 
> > >     pointer p;
> > >     int i;
> > > 
> > >     i = *p;
> > > 
> > > Does the memory pointed to by p contain a 4 byte integer, a 2 byte
> > > integer, or a 1 byte character, all of which can be assigned to an
> > > integer variable?
> > >
> > I guess the compiler would know it because when we define a variable
> > it is assigned a memory address. 
> >   so the compiler already know what is stored at address 10448 and 
> > what is stored at address 10566. 
> 
> But to handle something like:
> 
> int getValue(pointer p)
> {
>     return *p; // what type?
> }
> 
> the compiler would have to maintain a list of all memory addresses and
> the type of information in them.

To clarify- the compiler would generate code to maintain a run-time list.

John

Reply via email to