Path: utzoo!attcan!uunet!lll-winken!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: Broken compilers? (was Re: Comma Operator) Message-ID: <1907@buengc.BU.EDU> Date: 16 Jan 89 19:50:45 GMT References: <922@quintus.UUCP> <1904@buengc.BU.EDU> <15474@mimsy.UUCP> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c Organization: Boston Univ. Col. of Eng. Lines: 41 >-> printf("%d %d %d\n", (x = 1, y = 2), x, y); > >In article <1904@buengc.BU.EDU> bph@buengc.BU.EDU (Blair P. Houghton) writes: >-A while back, someone indicated that they knew of a compiler optimizer >-that would reduce something such as the above (ostensibly through >-constant-reduction) to >- >-printf("%d %d %d\n", (1,2), x, y); >- >-or maybe even >- >-printf("%d %d %d\n", 2, x, y); >- >-So, you compiler-writing C-programmers, is this thing broken or what? Chris Torek (chris@mimsy.UUCP) commands: [well, some of us think he found his copy of K&R I next to a burning bush...;-] >Quite thoroughly, unless both x and y are `dead'. > >The side effect(s), if any, of any expression that occurs anywhere >may not be arbitrarily deleted. If by "dead" you mean that the compiler has made a thorough search of the subsequently-traceable code, and the printf argument-heap is LIFO, so that it knows explicitly that x and y are never again referenced, then I think I follow you. Someone else emailed that explanation (one of these days I'll start remembering the names of the helpful people, sorry). It seems that we couldn't whine (nor could we tell without disassembling) if a really smart compiler reduced those expressions. Of course, if the side-effect of such a "dead" thing was that your PDP-8's eleventeenth-bit-light blinked, and that bulb was removed and the electrical contacts hooked to your Mr. Coffee controller, and your new artificially- intelligent compiler reduced the expression and unwittingly eliminated the blink, and you failed the CS 101 exam because of caffeine withdrawal... That would be injustice, eh? --Blair "I can't find 'Mr. Coffee' in the Syntax Summary..."