This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Is the order of parse '?:' operator not defined?
- From: "Dmitry K." <dmixm at marine dot febras dot ru>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 21 Dec 2008 17:43:01 +1000
- Subject: Is the order of parse '?:' operator not defined?
Hi,
Is the abort of program below correct?
Thanks,
Dmitry.
/* 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 ();
}