Path: utzoo!mnetor!uunet!husc6!bloom-beacon!athena.mit.edu!wesommer From: wesommer@athena.mit.edu (William E. Sommerfeld) Newsgroups: comp.lang.c Subject: A question about noalias and parameters. Message-ID: <2063@bloom-beacon.MIT.EDU> Date: 19 Dec 87 13:06:26 GMT Sender: daemon@bloom-beacon.MIT.EDU Reply-To: wesommer@athena.mit.edu (William E. Sommerfeld) Organization: Massachusetts Institute of Technology Lines: 61 A common use for passing pointers to functions is to provide a location for the function to stash a return value, or to provide something similar to VAR parameters in PASCAL or IN OUT parameters in ADA; this is useful if a function is to ``return'' multiple return values. In (pre-noalias) C, if one passes the address of a variable to a function, the compiler must assume that the variable must, from that point on, always be found at that address, because the function could have stashed the variable's address someplace where some other code expected to get at it later. Is giving a pointer parameter an attribute of ``noalias'' supposed to tell the compiler that the function is _not_ going to stash a copy of the parameter someplace where another function can get to it? In other words, are the two programs here supposed to be equivalent? program 1: void func(char *p1, char *p2, char **r1, char **r2); main() { register char *v1, *v2, *v3, *v4; ... some computations using v1, v2, v3, v4 ... { char *temp1 = v3; char *temp2 = v4; func(v1, v2, &temp1, &temp2); v3 = temp1; v4 = temp2; } ... more computations using v1, v2, v3, v4 ... } program 2: void func(char *p1, char *p2, noalias char **r1, noalias char **r2); main() { char *v1, *v2, *v3, *v4; ... some computations using v1, v2, v3, v4 ... func(v1, v2, &v3, &v4); ... more computations using v1, v2, v3, v4 ... } That is, could a compiler which does smart register allocation cause v3 and v4 to live in registers except for the duration of the call to func(), because it knows that other function calls will not be able to modify the values of v3 and v4? Bill Sommerfeld MIT Project Athena wesommer@athena.mit.edu