From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 110292,45b50f14dadfce5b X-Google-Attributes: gid110292,public X-Google-Thread: 102b75,45b50f14dadfce5b X-Google-Attributes: gid102b75,public X-Google-Thread: 1164f8,45b50f14dadfce5b X-Google-Attributes: gid1164f8,public From: Shankar Unni Subject: Re: Final kick at the "Merced Guessing Game" Date: 1997/10/14 Message-ID: <3443FAEF.EE62B663@powertelglobal.com>#1/1 X-Deja-AN: 280566470 References: <61g30t$o2n@news-rocq.inria.fr> <343C34A7.B715A348@tonys.ecology.umn.edu> <3440F805.C98BB347@tonys.ecology.umn.edu> <61tfaa$9fr@sis.cambridge.arm.com> <61uoiu$19e$1@goanna.cs.rmit.edu.au> X-Trace: 876870498 18522 (none) 206.86.0.12 Organization: Powertel Global, Inc. Newsgroups: comp.sys.intel,comp.arch,comp.sys.dec Richard A. O'Keefe wrote: > > bool = !(!f() | (!g() & !h())); > > In a word, NO. The C version absolutely requires all of the function > calls to be performed. First of all, this is true for "&" and "|", but not "&&" or "||". I'm sure you knew that. (Does Fortran allow .AND. of INTEGER variables, or only LOGICAL variables? If the latter, then "&" is a bad analog anyway). Secondly, even for "&" (or "*", as in the 0*f() example) , it can elide the call if the effect is the same whether it had or had not called the function. I.e. if the compiler *knows* that the function has no side effects (either by deduction, or by programmer intervention), it can skip the call. Thus, in static int foo() { return 10; } ... for (i = 1; i <= 1000; i++) { (void) 0*f(); } the compiler is allowed to boil down the entire loop into nothing. And in fact, it does, using Sun cc. (gcc 2.7.2 is a little stupid: it removes the call, but leaves an empty loop behind!) Other such optimizations are also allowed: if the function had been static int foo() { return globalvariable = 10; } then the entire loop can be boiled down into globalvariable = 10; (The point is that yes, you can create contrived examples in which C is not allowed to optimize what Fortran is, but sophisticated compiler analysis can make up for a lot of these problems. Not a panacea, but it's better than nothing.) -- Shankar Unni Powertel Global, Inc. (650) 259-1700 shankar@powertelglobal.com (650) 259-1702 (fax) shankar@webnexus.com