Agree, when the value is unwanted explicitly, the generate WHIRL is just the
same, i.e.

#include<stdio.h>
#include<stdlib.h>
int main()
{
  int i = rand();
  printf("i = %i\n", i);
  if (i)
    printf("i = %i\n", i);
  return 0;
}



On Thu, Oct 7, 2010 at 1:02 PM, Handong Ye <yehand...@gmail.com> wrote:

> A wild guess. The code needs the return value of second printf as its
> return value, if 2nd printf is the last statement.
>
> 2010/10/6 Fred Chow <frdc...@gmail.com>:
> > We just generate the WHIRL according to what is given to us in GNU
> > tree/spin.  So it is GNU's C front-end that has this discrepancy.
> >
> > Fred
> >
> > On 10/06/2010 01:34 AM, "C. Bergström" wrote:
> >> I'm forwarding this question..
> >>
> >> ELSE block removed to shorten the example..
> >> ----------
> >>
> >> when I have code like this:
> >>
> >>    int i = rand();
> >>    printf("i = %i\n", i);
> >>    if (i)
> >>      printf("i = %i\n", i);
> >>
> >> (a subset of ) the generated whirl code is:
> >>
> >>     U8LDA 0<1,44,(8_bytes)_"i_=_%i\n\000">  T<50,anon_ptr.,8>
> >>    U8PARM 2 T<44,anon_ptr.,8>  #  by_value
> >>     I4I4LDID 0<2,3,i>  T<4,.predef_I4,4>
> >>    I4PARM 2 T<4,.predef_I4,4>  #  by_value
> >>   VCALL 126<1,43,printf>  # flags 0x7e
> >>
> >>   IF
> >>     I4I4LDID 0<2,3,i>  T<4,.predef_I4,4>
> >>     I4INTCONST 0 (0x0)
> >>    I4I4NE
> >>   THEN
> >>    BLOCK
> >>      BLOCK
> >>        U8LDA 0<1,44,(8_bytes)_"i_=_%i\n\000">  T<50,anon_ptr.,8>
> >>       U8PARM 2 T<44,anon_ptr.,8>  #  by_value
> >>        I4I4LDID 0<2,3,i>  T<4,.predef_I4,4>
> >>       I4PARM 2 T<4,.predef_I4,4>  #  by_value
> >>      I4CALL 126<1,43,printf>  # flags 0x7e
> >>      END_BLOCK
> >>      I4I4LDID -1<1,40,.preg_return_val>  T<4,.predef_I4,4>
> >>     I4COMMA
> >>    EVAL
> >>    END_BLOCK
> >>
> >>
> >> What I don't understand is why there is a difference between the first
> and second
> >> printf calls. The second call is loading the return value of the
> function being
> >> called while the second one ignores that. It also enforces evaluation
> via
> >> eval node. Why? What is the difference between plain printf() and
> printf() in if-block ?
> >>
> >> ---------
> >>
> >> Thanks
> >>
> >> ./C
> >>
> >>
> ------------------------------------------------------------------------------
> >> Beautiful is writing same markup. Internet Explorer 9 supports
> >> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2&  L3.
> >> Spend less time writing and  rewriting code and more time creating great
> >> experiences on the web. Be a part of the beta today.
> >> http://p.sf.net/sfu/beautyoftheweb
> >> _______________________________________________
> >> Open64-devel mailing list
> >> Open64-devel@lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/open64-devel
> >>
> >
> >
> >
> ------------------------------------------------------------------------------
> > Beautiful is writing same markup. Internet Explorer 9 supports
> > standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
> > Spend less time writing and  rewriting code and more time creating great
> > experiences on the web. Be a part of the beta today.
> > http://p.sf.net/sfu/beautyoftheweb
> > _______________________________________________
> > Open64-devel mailing list
> > Open64-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/open64-devel
> >
>
>
>
> --
> Thanks.
> Handong
>
>
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
> Spend less time writing and  rewriting code and more time creating great
> experiences on the web. Be a part of the beta today.
> http://p.sf.net/sfu/beautyoftheweb
> _______________________________________________
> Open64-devel mailing list
> Open64-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/open64-devel
>
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to