Path: utzoo!utgpu!watmath!att!dptg!rutgers!iuvax!purdue!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.std.c Subject: Re: Semi constant expressions Keywords: expressions, optimization, code generation Message-ID: <10885@smoke.BRL.MIL> Date: 31 Aug 89 00:34:47 GMT References: <1237@gmdzi.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 17 In article <1237@gmdzi.UUCP> wittig@gmdzi.UUCP (Georg Wittig) writes: > 0 * x (x non-constant) > 0 / x > x << (100000000L) > etc. >Does (p)ANSI C say anything about which code should be generated for such >expressions? This falls naturally out of the specification. The operands ARE evaluated, so if `x' has side-effects they do occur. If evaluation would produce what the Standard labels as "undefined behavior", then the implementation can do anything it likes including taking short cuts, but in cases where the behavior is well defined the only short cuts permitted are those that produce the same results as doing it the long way. The Standard neither prohibits nor requires optimizations. It prescribes what the program behavior must be.