Re: Address taken And aliasing

Marco van de Voort <marcov@snail.stack.nl>
18 May 2003 23:54:28 -0400

          From comp.compilers

Related articles
Address taken And aliasing ednaprs@yahoo.ca (2003-05-15)
Re: Address taken And aliasing marcov@snail.stack.nl (Marco van de Voort) (2003-05-18)
| List of all articles for this month |
From: Marco van de Voort <marcov@snail.stack.nl>
Newsgroups: comp.compilers
Date: 18 May 2003 23:54:28 -0400
Organization: Eindhoven University of Technology, The Netherlands
References: 03-05-102
Keywords: practice
Posted-Date: 18 May 2003 23:54:27 EDT

I'm no expert, but I'll try :-)


Ednap wrote:
> I, every and then, hear about "address taken" in programming languages
> and compilers.


It's pretty much creating a reference to some symbol (variable, or
part of it, like a field of a record). One way is e.g. the C operator
&, but in other languages there are more.


> I wanted to know what exactly it meant.


The general idea is keeping an memory location (or a measure for that) to
a variabele in a different variabele or register.


> And I also
> wanted to know the relationship between address taken and aliasing
> information that front end of the compiler generates.


E.g. If I take the address somewhere, I mark the new variabele as an alias of
the other.


Assume we have this. (in pascal'ish syntax, @ is the same as & in C)


var number : Integer;
        othernumber : Integer;
        ref : ^Integer; // pointer


Begin
    number:=10;
    ref:=@number; // take address.
    while number>0 Do
        Begin
            Writeln(ref^); // print value the pointer points to.
            Dec(Number);
        End;


Assume we have no knowledge of ref pointing to number.


We could then optimise this loop by moving number to some register and
decrement it ten times.


However that would give a different result, since Writeln(ref^) is supposed
to print the value of Number.


Because we marked ref as an alias to number, we know how far we can go with
optmizing.


(what code exactly will be generated depends on the quality of the
optimizer, and how the printing runtime routine wants its parameters, which
registers it spoils etc.


If the printing routine simply wants the argument in a register, and saves
all other regs, we can still safely optimize and put number in a register)


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.