Path: utzoo!utgpu!water!watmath!clyde!rutgers!lll-lcc!ames!ucbcad!zodiac!sri-spam!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: a couple quickies Summary: loop should execute 0 times Message-ID: <510@cresswell.quintus.UUCP> Date: 8 Jan 88 01:25:30 GMT References: <11145@brl-adm.ARPA> Organization: Quintus Computer Systems, Mountain View, CA Lines: 49 In article <11145@brl-adm.ARPA>, PEPRBV%CFAAMP.BITNET@husc6.harvard.EDU (Bob Babcock) writes: > TLIMONCE%DREW.BITNET@CUNYVM.CUNY.EDU asks > >>Question: Under ANSI C, > >> for (i = 0; i == 100; i++) foo(&i); > >>If foo() does something like: "*i = 0" will this loop ever complete? > >>I hope this is classified as undefined. > > Seems to me that this is well defined, and the loop should never > terminate. But I'm not sure that the answer doesn't change if i > is declared noalias. I thought a loop like this was supposed to be equivalent to { i = 0; while (i == 100) { foo(&i); i++; } } Since 0 != 100, the body of the loop should never be executed, so it had *better* terminate! Just to keep the 'noalias' pot boiling, I asked what makes C so special that it needs 'noalias' when Fortran doesn't, and someone said "Pointers!". Unfortunately, that is not an adequate answer. It has been known for a long time that pointers and array elements cause exactly the same problems with respect to aliasing. (For example, a Euclid program is, strictly speaking, legal only if the I =\= J verification conditions the compiler generates to express "no aliasing through array indices" are provable.) What I mean by this is that if we have float a[1000]; float fred(int i, int j) { float x; x = a[i]; a[j] -= 1.0; return x + a[i]; } Is it safe to translate the last expression as x+x? Only if i != j. Ok, this is a contrived example, but the opportunity arises again and again in typical numerical code. (It is a really big problem for vectorising compilers.) So tell me, how do I use the 'noalias' directive to tell a C compiler it is safe to assume i != j here? And if 'noalias' cannot be used to tell the compiler that there is no aliasing here, what good is it?