Discussion:
Precedence of GNU C++ extensions >? and <? (min/max operators)
Jeremy Hall
2011-03-05 10:07:01 UTC
Permalink
Hi,

Does anyone know the exact priority of these operators? Its not
mentioned in the
description of the extension as far as I can see.

Thanks
Jeremy
Axel Freyn
2011-03-05 15:51:10 UTC
Permalink
Hi Jeremy,
Post by Jeremy Hall
Does anyone know the exact priority of these operators? Its not
mentioned in the description of the extension as far as I can see.
As I read the documentation in the gcc-sourcecode, they are the same
precedence as "<", ">", "<=", ">=". They are relation operators and
form a "relational-expression": (ยง5.9 in C++ standard, [expr.rel])

See line 6258-6296 in
http://gcc.gnu.org/viewcvs/branches/gcc-4_5-branch/gcc/cp/parser.c?view=markup&revision=170622
relational-expression:
shift-expression
relational-expression < shift-expression
relational-expression > shift-expression
relational-expression <= shift-expression
relational-expression >= shift-expression

GNU Extension:

relational-expression:
relational-expression <? shift-expression
relational-expression >? shift-expression


HTH,

Axel
Bob Plantz
2011-03-05 16:27:13 UTC
Permalink
Post by Jeremy Hall
Hi,
Does anyone know the exact priority of these operators? Its not
mentioned in the
description of the extension as far as I can see.
Thanks
Jeremy
I always told my students that multiplication and division have
higher precedence than addition and subtraction. Use
parentheses everyplace else. Code readability was part of
their grade in my classes.

--Bob
Jeremy Hall
2011-03-05 17:38:43 UTC
Permalink
Thanks for looking this up Axel,
Exactly the info I needed.
(I am writing an arithmetic expression interpreter).

Regards
Jeremy

Loading...