Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site reed.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!tektronix!reed!joey From: joey@reed.UUCP (Joe Pruett) Newsgroups: net.lang.c Subject: Optimization error? Message-ID: <3109@reed.UUCP> Date: Thu, 17-Apr-86 19:56:50 EST Article-I.D.: reed.3109 Posted: Thu Apr 17 19:56:50 1986 Date-Received: Sat, 19-Apr-86 13:18:11 EST Reply-To: joey@reed.UUCP (Joe Pruett) Distribution: net Organization: Reed College, Portland, Oregon Lines: 37 We recently discovered an interesting gotcha in the Apollo C compiler. We had code similar to this: func(x) int x; { int flag; if (x < 0) { printf("Bad news\n"); } else { flag = 1; } do { printf("Hello, world.\n"); } while (!flag); } Yes, there is an error in that flag may not get set before it is used. I was horrified to find out that lint won't catch this kind of an error. Anyway, the interesting part is that the compiler determined that the expression !flag would always be 0, and therefore optimized it away causing the do-while loop to exit after one pass. I contend that if the compiler could figure out that flag could get set to 1, then it should also figure out that flag might not bet set to anything, and at least issue a warning, but it should not optimize the expression away. Is this a bug, or a misfeature, or an inherent gotcha with fancy optimization? -- Joe Pruett Test Systems Strategies, Inc. ...!tektronix!reed!tessi!joey