RE: Rank of && and ||

From: Stefano Bettelli (bettelli@tn.infn.it)
Date: Wed Mar 01 2000 - 16:59:34 MET


On 01-Mar-00 Masayuki Etoh wrote:
> Dear ROOTers,
> 
> I tried the following macro on ROOT-2.23/11 and cint, I got "FALSE".
> It should be "TRUE", right?
        C++ reference manuals state that && has precedence over ||,
        so (a==0 && a==0 || a==1) means ((a==0 && a==0) || a==1) and
        the expression should be evaluated to TRUE (since a is 1).
        I see the following (wrong) behaviour on ROOT:

        root [1] int a=1;
        root [2] if (a==0 && a==0 || a==1)   printf("TRUE\n"); else printf("FALSE\n");
        FALSE
        root [3] if (a==0 && (a==0 || a==1)) printf("TRUE\n"); else printf("FALSE\n");
        FALSE
        root [4] if ((a==0 && a==0) || a==1) printf("TRUE\n"); else printf("FALSE\n");
        TRUE

        The same program compiled with GNU g++ gives the correct sequence:

        TRUE FALSE TRUE
                                                Stefano Bettelli

----------------------------------------------------------
E-Mail: Stefano Bettelli <bettelli@tn.infn.it>
WWW   : http://meitner.tn.infn.it/~bettelli



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:20 MET