Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ames!amdcad!crackle!tim From: tim@crackle.amd.com (Tim Olson) Newsgroups: comp.lang.c Subject: Re: programming puzzle (silly) Message-ID: <24820@amdcad.AMD.COM> Date: 11 Mar 89 19:57:01 GMT References: <28336@ucbvax.BERKELEY.EDU> <2821@goofy.megatest.UUCP> Sender: news@amdcad.AMD.COM Reply-To: tim@amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc. Sunnyvale CA Lines: 30 Summary: Expires: Sender: Followup-To: In article bader+@andrew.cmu.edu (Miles Bader) writes: | From klier@ucbarpa.Berkeley.EDU (Pete Klier): | > | > main(m,n){scanf("%d",&n);for(m=n>0^n>9;n&&m*=n--;); | > printf(m?"Answer=%d\n":"error\n",m);} | > | > with help from Jeff Conroy (jmconroy@ernie.Berkeley.EDU) | | The compiler on this machine give the following error; is it wrong? | | E "fact.c",L1/C44: (syntactic) unexpected symbol:'*=' Interesting -- the program *is* incorrect, because && has higher precedence than *= so it is parsed as: (n&&m) *= n-- which is illegal because (n&&m) is not an lvalue. Our MetaWare and Green Hills compilers catch it, but every pcc-based compiler I tried compiled it with no warnings. Looking at the assembly-language generated, it appears that it compiled as: n && (m*=n--) What do other compilers out there do? -- Tim Olson Advanced Micro Devices (tim@amd.com)