Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: comp.lang.c Subject: Re: short circuit evaluation Message-ID: <7588@utzoo.UUCP> Date: Fri, 30-Jan-87 17:08:26 EST Article-I.D.: utzoo.7588 Posted: Fri Jan 30 17:08:26 1987 Date-Received: Fri, 30-Jan-87 17:08:26 EST References: <425@bobkat.UUCP> <102600001@datacube> <34@umich.UUCP> <5178@mimsy.UUCP>, <484@bobkat.UUCP> Organization: U of Toronto Zoology Lines: 19 > x = f1(something) * f2(something) * f3(something) ... > > Shouldn't I expect all the multiplications to be performed, even if one > function returns zero? > I don't think I've ever used a compiler that does such optimizations... > ... Has anyone else? Yeah, some variants of the V7 pdp11 C compiler did, in cases where one of the operands was a compile-time constant known to be 0. (This can arise legitimately when doing arithmetic on configuration-dependent #defined constants, for example.) Never bothered me, since I view side effects inside expressions as being unjustifiable pornography except for some very specific cases. I did ask Dennis about it at one point, since strict reading of K&R suggested it was a bug. His reply, as I recall it, was roughly "I think it is defensible in principle, but it caused so many complaints that newer versions of the compiler don't do it". -- Legalize Henry Spencer @ U of Toronto Zoology freedom! {allegra,ihnp4,decvax,pyramid}!utzoo!henry