This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is the order of parse '?:' operator not defined?


Dmitry K. wrote:

> Is the abort of program below correct?

I think it 's a bug.  Forwarding to Tom tromey for comment.

Andrew.


> /* This program is aborted with GCC 3.4.6.  Also it is checked that
>    '#if foo(1) == bar(1)' is evaluted as false with a set of 3.3 - 4.3
>    releases.  Seems, the CPP and CC parsers are different in case of
>    foo() macro.
> 
>    C99 standart:
>         6.5.15 Conditional operator
>         Syntax
>             conditional-expression:
>                 logical-OR-expression
>                 logical-OR-expression ? expression : conditional-expression
>  */
> 
> extern void abort (void);
> 
> #define foo(x)  ((x) & 1 ? 1 :  (x) & 2 ? 2 : 0 )
> #define bar(x)  ((x) & 1 ? 1 : ((x) & 2 ? 2 : 0))
> 
> int main ()
> {
> #if foo (1) == bar (1)
>   return 0;
> #endif
>   if (foo (1) != bar (1))
>     return 0;
> 
>   abort ();
> }
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]