【正文】
? } Compiler Theory Fall 2021 Jianhui Yue free ( void *ap ) ? { Header *bp,*p,*prev。 ? p=0。 ? /* initiate the first header */ ? /* search the list with the first fit , the p points to the first fit block */ ? newp=p+p 。 }。 }。x。 return amp。 virtual void g()。 virtual void h()。 ? nunits= ( nbytes+sizeof(Header)1)/sizeof(Header ) + 1。 ? newp=p。 ? return (void *) (newp+1)。 ? prev=p。} /* incorrect */ void inc2(int* x) { ++x。 Compiler Theory Fall 2021 Jianhui Yue Pass by Reference ? Pass by reference passes the location of the variable, so that the parameter bees an alias for the argument. ? Any changes made to parameter occur to the argument as well. ? This is the only parameter passing in FORTRAN77. void inc2(int amp。 Compiler Theory Fall 2021 Jianhui Yue Pass by Reference (cont) ? The piler must – Compute the address of the argument – Store it in the local activation record – Turn local accesses to a reference parameter into indirect accesses ? No copy of the passed value is made. – This is significant when the parameter is a large structure. Compiler Theory Fall 2021 Jianhui Yue Pass by ValueResult ? Similar to pass by reference. ? No actual alias is established – The value of the argument is copied and used in the procedure – On exit the final value of the parameter is copied back out to the location of the argument. ? This method is known as copyin, copyout or copyrestore. void p(int x, int y) { ++x。 return 0。} main() { i=1。 } a[2] is set to 3 a[1] is unchanged Compiler Theory Fall 2021 Jianhui Yue Pass by Name (cont) ? Pass by name was offered in Algol60, but bee unpopular. 1. It can give surprising and counterintuitive results in the presence of the side effects. 2. It is difficult to implement – Each argument must be turned into the procedure 3. It is inefficient ? A variation on this mechanism called lazy evaluation bee popular in purely functional languages (Miranda, Haskell) Compiler Theory Fall 2021 Jianhui Yue Homework ? ,