Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

min/max operators priority

25 views
Skip to first unread message

Jeremy Hall

unread,
Mar 5, 2011, 3:03:34 PM3/5/11
to

Hi,

GNU C++ has two binary operators >? and <? which provide min and max
but without any issues with
side effects as the normal macros have.

My question is, does any one know the exact priority of these
operators ?
Its not documented as far as I can see.

Thanks
Jeremy


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

red floyd

unread,
Mar 6, 2011, 2:06:42 PM3/6/11
to
On 3/5/2011 12:03 PM, Jeremy Hall wrote:
>
> Hi,
>
> GNU C++ has two binary operators>? and<? which provide min and max
> but without any issues with
> side effects as the normal macros have.
>
> My question is, does any one know the exact priority of these
> operators ?
> Its not documented as far as I can see.

Use std::min and std::max. They don't have any side effects either,
and they're not limited to one implementation, and they're fully
documented in the Standard.

Also, IIRC, <? and >? are deprecated.

marcin...@gmail.com

unread,
Mar 6, 2011, 2:06:32 PM3/6/11
to
On 5 Mar, 21:03, Jeremy Hall <gcc.h...@gmail.com> wrote:
> Hi,
>
> GNU C++ has two binary operators >? and <? which provide min and max
> but without any issues with
> side effects as the normal macros have.
>
> My question is, does any one know the exact priority of these
> operators ?
> Its not documented as far as I can see.
>
> Thanks
> Jeremy
>
Hi Jeremy

In such situation it's always a good idea to use parentheses. But
intuitivly they should have same priority as less/greater then
operators.

Nevertheless I would rather use std::min and std::max from STL.
These are functions which don't suffer from the same problems
as macros, but should be inlined so there should be no overhead.

Cheers,
Marcin

Keith Thompson

unread,
Mar 6, 2011, 2:04:33 PM3/6/11
to
Jeremy Hall <gcc....@gmail.com> writes:
> GNU C++ has two binary operators >? and <? which provide min and max
> but without any issues with
> side effects as the normal macros have.
>
> My question is, does any one know the exact priority of these
> operators ?
> Its not documented as far as I can see.

Quoting the gcc documentation:

The G++ minimum and maximum operators (`<?' and `>?') and their
compound forms (`<?=') and `>?=') have been deprecated and are
now removed from G++. Code using these operators should be
modified to use `std::min' and `std::max' instead.

That's not to say your question isn't valid, but it may be difficult
to get an answer. Your best bet is either to read an older version
of the gcc documentation (perhaps you've already done that), or to
experiment with an older version of g++ that still supports them.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

der...@cix.compulink.co.uk

unread,
Mar 7, 2011, 8:40:35 AM3/7/11
to

>From the gcc 4.5.2 manual section 7.11

The G++ minimum and maximum operators (`<?' and `>?') and their compound
forms (`<?=') and `>?=') have been deprecated and are now removed from
G++. Code using these operators should be modified to use std::min and
std::max instead.

So it doesn't really matter what their precedence is!

> *From:* Jeremy Hall <gcc....@gmail.com>
> *To:* undisclosed-recipients:;
> *Date:* Sat, 5 Mar 2011 14:03:34 CST

Daniel Krügler

unread,
Mar 7, 2011, 12:09:37 PM3/7/11
to

On 2011-03-06 20:06, red floyd wrote:
> On 3/5/2011 12:03 PM, Jeremy Hall wrote:
>>
>> Hi,
>>
>> GNU C++ has two binary operators>? and<? which provide min and max
>> but without any issues with
>> side effects as the normal macros have.
>>
>> My question is, does any one know the exact priority of these
>> operators ?
>> Its not documented as far as I can see.
>
> Use std::min and std::max. They don't have any side effects either,
> and they're not limited to one implementation, and they're fully
> documented in the Standard.
>
> Also, IIRC, <? and >? are deprecated.

I agree that std::min/std::max should be used, where possible instead
of compiler-specific extensions like <? and >?. One possible reason for
still needing to use the extension forms is, when the min/max evaluation
has to open in a constant expression (I don't know these extension
functions, but I assume that they can be used in constant expressions).
Unfortunately std::min/std::max are not (yet) constexpr functions. This
may also be tricky, depending on the current evolution of the core-rules
in regard to constexpr functions.

Greetings from Bremen,

Daniel Krügler

red floyd

unread,
Mar 8, 2011, 2:52:26 PM3/8/11
to
On 3/7/2011 9:09 AM, Daniel Kr�gler wrote:
>
> On 2011-03-06 20:06, red floyd wrote:
>
>> Use std::min and std::max. They don't have any side effects either,
>> and they're not limited to one implementation, and they're fully
>> documented in the Standard.
>>
> One possible reason for
> still needing to use the extension forms is, when the min/max evaluation
> has to open in a constant expression (I don't know these extension
> functions, but I assume that they can be used in constant expressions).
> Unfortunately std::min/std::max are not (yet) constexpr functions. This
> may also be tricky, depending on the current evolution of the core-rules
> in regard to constexpr functions.
>

In that case, I'd use a macro, since there should be no side effects for
a const expression.

Richard Smith

unread,
Mar 8, 2011, 7:59:21 PM3/8/11
to

On Mar 5, 8:03 pm, Jeremy Hall <gcc.h...@gmail.com> wrote:

> GNU C++ has two binary operators >? and <? which provide min and max
> but without any issues with side effects as the normal macros have.
>
> My question is, does any one know the exact priority of these

> operators? Its not documented as far as I can see.

They're not just deprecated: they've been removed entirely from recent
versions of gcc. As others have said, you should consider using
std::max and std::min instead, but be aware that some (old or badly
behaved) headers may #define symbols called max and min. To answer
your question, they were in their own precedence level between == and
& and were left-to-right associative. It was possible to overload the
operators using the obvious syntax.

--
Richard Smith

Seungbeom Kim

unread,
Mar 8, 2011, 8:00:34 PM3/8/11
to

On 2011-03-07 09:09, Daniel Krügler wrote:
>
> On 2011-03-06 20:06, red floyd wrote:
>>
>> Also, IIRC, <? and >? are deprecated.
>
> I agree that std::min/std::max should be used, where possible instead
> of compiler-specific extensions like <? and >?. One possible reason for
> still needing to use the extension forms is, when the min/max evaluation
> has to open in a constant expression (I don't know these extension
> functions, but I assume that they can be used in constant expressions).
> Unfortunately std::min/std::max are not (yet) constexpr functions. This
> may also be tricky, depending on the current evolution of the core-rules
> in regard to constexpr functions.

I remember hearing lots of other "imperfections" with std::{min,max},
besides this. For example, std::min(1, 1L) doesn't compile, and neither
does ++std::min(x, y) (By the way, why isn't there a non-const overload?),
while both are possible in the macro version.

Basically, we want to be able to do whatever we can do with the macro
version, minus all the pitfalls of macros. And the template function
solution hasn't been able to meet the needs.

Can anyone tell why <? and ?> have been deprecated and removed from GCC?
I think they could be useful at times, though std::{min,max} will work
*most* of the time.

--
Seungbeom Kim

Daniel Krügler

unread,
Mar 9, 2011, 3:53:16 AM3/9/11
to
Am 08.03.2011 20:52, schrieb red floyd:

> On 3/7/2011 9:09 AM, Daniel Krügler wrote:
>>
>> On 2011-03-06 20:06, red floyd wrote:
>>
>>> Use std::min and std::max. They don't have any side effects either,
>>> and they're not limited to one implementation, and they're fully
>>> documented in the Standard.
>>>
>> One possible reason for
>> still needing to use the extension forms is, when the min/max evaluation
>> has to open in a constant expression (I don't know these extension
>> functions, but I assume that they can be used in constant expressions).
>> Unfortunately std::min/std::max are not (yet) constexpr functions. This
>> may also be tricky, depending on the current evolution of the core-rules
>> in regard to constexpr functions.
>>
>
> In that case, I'd use a macro, since there should be no side effects for
> a const expression.

Personally I would appreciate if std::min/std::max became constexpr
functions for exactly these kind of purposes. One argument for providing
constexpr functions was to remove the second-class citizen status of
functions in constant expressions as outlined in

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf

Actually the core-language state of the most recent draft *would* allow
for making these functions constexpr. But it is too late for C++0x to
make std::min/std::max constexpr-capable.

Greetings from Bremen,

Daniel Krügler


0 new messages