Path: utzoo!attcan!uunet!lll-winken!ames!amdahl!amdcad!crackle!tim From: tim@crackle.amd.com (Tim Olson) Newsgroups: comp.lang.c Subject: Re: Broken compilers? (was Re: Comma Operator) Message-ID: <24088@amdcad.AMD.COM> Date: 16 Jan 89 23:01:57 GMT References: <922@quintus.UUCP> <1904@buengc.BU.EDU> <15474@mimsy.UUCP> <1907@buengc.BU.EDU> Sender: news@amdcad.AMD.COM Reply-To: tim@crackle.amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc. Sunnyvale CA Lines: 31 Summary: Expires: Sender: Followup-To: In article <1907@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: | 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... Nah, just remember to declare it "volatile": volatile int PDP_11th_light_kludged_into_Mr_Coffee_Machine; ;-) Dead code elimination does have other useful benefits. I was looking over some assembly code generated by the MetaWare Am29000 C compiler from proprietary sources that a large company had given us, and was able to catch the error in the following code, because the compiler generated no instructions for it other than the return! foo(myColor, index) RGB *myColor; long *index; { if ((myColor->red + myColor->green + myColor->blue)/3 <= (MAXRGB/2)) *index++; } -- Tim Olson Advanced Micro Devices (tim@crackle.amd.com)