This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Is the order of parse '?:' operator not defined?
- From: Andrew Haley <aph at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sun, 21 Dec 2008 17:47:12 +0000
- Subject: Re: Is the order of parse '?:' operator not defined?
- References: <200812211743.01414.dmixm@marine.febras.ru>
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 ();
> }
>