Path: utzoo!utgpu!water!watmath!clyde!rutgers!rochester!cornell!uw-beaver!mit-eddie!husc6!hao!noao!arizona!mike From: mike@arizona.edu (Mike Coffin) Newsgroups: comp.lang.c Subject: Re: More on noalias Summary: It can already be done Message-ID: <3433@megaron.arizona.edu> Date: 12 Jan 88 20:34:26 GMT References: <10129@mimsy.UUCP> Organization: U of Arizona CS Dept, Tucson Lines: 38 In article <10129@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > First, let me construct an example in which aliasing is relatively > hard to detect. How about this: > > void > vector_add /* maybe */ (int *a, int i, int j, int k, int n) > { > > for (; --n >= 0; i++, j++, k++) > a[i] = a[j] + a[k]; > } > > This can use a vector add iff i != j and i != k (on some hypothetical > machine). Hence the compiler wants to know whether this will be > true. By declaring `int *noalias a' or `noalias int *a' (whichever > it is), we could say that. I wish I knew for sure what noalias meant. In any case, you can already (in good old K&R C) write the above function in a way that allows vector add: void vector_add /* maybe */ (int *a, int i, int j, int k, int n) { if (i==j || i==k) return; /* now the compiler can infer that i!=j and i!=k */ for (; --n >= 0; i++, j++, k++) a[i] = a[j] + a[k]; } If you don't like the way the if-statement looks, embed it in a macro; e.g., "opt_assert(i!=j && i !=k)". -- Mike Coffin mike@arizona.edu Univ. of Ariz. Dept. of Comp. Sci. {allegra,cmcl2,ihnp4}!arizona!mike Tucson, AZ 85721 (602)621-4252