37

I observed that there was at some point a <? and >? operator in GCC. How can I use these under GCC 4.5? Have they been removed, and if so, when?

Offset block_count = (cpfs->geo.block_size - block_offset) <? count;
cpfs.c:473: error: expected expression before ‘?’ token
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526

2 Answers2

38

Recent manuals say:

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.

A quick search of the past documents seems to indicate that they were removed around version 4.0 (3.4.6 includes them, 4.0.4 does not).

Barry
  • 286,269
  • 29
  • 621
  • 977
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • @Matt Joiner, That's what the docs say, yes: "GNU C++ (but not in GNU C)". – Carl Norum Aug 09 '10 at 14:01
  • 4
    I'd like to give +1 if you can provide a link. – Matt Joiner Aug 09 '10 at 16:53
  • 2
    @Matt Joiner, SRSLY? How about google? Here: http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/ – Carl Norum Aug 09 '10 at 16:54
  • Yeah... it's sad that it was removed. `a = b;` was a neat trick! Super concise and easy to read. Okay... `a = std::min(a, b);` is not that bad either. 8-) – Alexis Wilke Jan 30 '12 at 05:17
  • 6
    That's not that sad, because one could spend looong time trying to understand what the hell this code is doing, if he hadn't known gnu extensions. – cubuspl42 Apr 26 '13 at 20:08
  • 5
    @CarlNorum: One should be citing with a link in the first place. – Matt Joiner Feb 10 '14 at 08:22
  • @cubuspl42 and searching for code containing ``, `>?`, `=`, and/or `>?=` on Google might be hard because Google doesn't always play well with symbols. – RastaJedi May 12 '16 at 05:35
  • 1
    @AlexisWilke but I must admit, it does look a cool neat trick and I would definitely use it for the same purpose as OP if it wasn't replaced/deprecated. – RastaJedi May 12 '16 at 05:56
8

Earlier iterations of g++ (not the C compiler) used these operators for giving you the minimum or maximum values but they've long been deprecated in favour of std::min and std::max.

Basically, they equated to (but without the possibility of double evaluation of a or b):

a <? b       -->       (a < b) ? a : b
a >? b       -->       (a > b) ? a : b

In terms of replacing them (and you really should replace them), you can use something like:

Offset block_count = cpfs->geo.block_size - block_offset;
if (block_count > count) block_count = count;

or equivalents using std::min.

I'm not a big fan of using C/C++ "extensions" (especially ones that have been deprecated and/or removed) since they tie me to a specific implementation of the language.

You should never use a non-standard extension where a perfectly adequate standard method is available.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953