Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!hagbard!sunic!news.funet.fi!uta!kielo!av From: av@kielo.uta.fi (Arto V. Viitanen) Newsgroups: comp.lang.c Subject: Re: When do you use "if ( a = b )"? (was Re: Funny mistake) Message-ID: Date: 22 Mar 91 07:49:47 GMT References: <8148@rsiatl.Dixie.Com> <15481@smoke.brl.mil> <775@camco.Celestial.COM> <65837@eerie.acsu.Buffalo.EDU> <1991Mar18.195351.11985@unlv.edu> <11109@dog.ee.lbl.gov> <11204@dog.ee.lbl.gov> Sender: news@uta.fi Reply-To: av@uta.fi (Arto V. Viitanen) Organization: University of Tampere, Finland Lines: 94 Nntp-Posting-Host: uta.fi In-reply-to: torek@elf.ee.lbl.gov's message of 20 Mar 91 21:45:46 GMT >>>>> On 20 Mar 91 21:45:46 GMT, torek@elf.ee.lbl.gov (Chris Torek) said: Chris> X-Local-Date: Wed, 20 Mar 91 13:45:47 PST Chris> In article av@uta.fi (Arto Viitanen) writes: Chris> [gcc version 1.39 on Sun-3, compiling `if (a = b)' vs `a = b; if (a)'] >In GNU cc, it was other way round: without optimization, assembler code >was same, but with optimization, they were different. Chris> That is peculiar. I tried the same thing, with the same gcc, on the Chris> same machine, and got identical code when optimized, different (poorer) Chris> code for the second when not, exactly as expected. Yes, you are right. I mixed somewhere result assembler codes; actually both SUN's and GNU's generate different codes without optimization and similar with optimization. What is more interesting, is the difference between codes of SUN and GNU: when C program is: #include main () { int a,b; a = 1; if(a=b) printf("yes\n"); } , SUN's C compiler (SUN 3, SunOS 4.0.3) generates .data .text LL0: .proc |#PROC# 04 .data1 L29: .ascii "yes\012\0" LF25 = 8 LS25 = 0 LFF25 = 8 LSS25 = 0 LV25 = 8 .data .text .globl _main _main: |#PROLOGUE# 0 link a6,#-8 |#PROLOGUE# 1 moveq #1,d1 movl d1,a6@(-4) movl a6@(-8),a6@(-4) jeq L27 pea L29 jbsr _printf addqw #4,sp L27: moveq #0,d0 |#PROLOGUE# 2 unlk a6 |#PROLOGUE# 3 rts but gcc (version 1.39) generates #NO_APP gcc_compiled.: .text LC0: .ascii "yes\12\0" .even .globl _main _main: link a6,#0 tstl d0 jeq L2 pea LC0 jbsr _printf L2: unlk a6 rts It seems than GCC drops the whole test away !! -- Arto V. Viitanen email: av@kielo.uta.fi University Of Tampere, av@ohdake.cs.uta.fi Finland