Strange use of conditional operator (>? =)

I looked at some code and saw something like this:

int d = 1; int somethingbigger = 2; d >?= somethingbigger; cout << d << endl; 

I think this should output 2. But I can't even compile this with gcc 4.5.2. The code was written in 2005 and compiled with gcc 3.4.4 (not 100% sure).

Can someone explain how this works and why I cannot compile this with a recent compiler.

+4
source share
3 answers

This is the "maximum" assignment operator, a GCC extension .

  • If the extension is not enabled, you cannot use this feature.

  • Starting with version 4.0.1 :

    The minimum and maximum g ++ operators ( <? And >? ) And their composite forms ( <?= ) And >?= ) >?= deprecated and will be removed in a future version . Code using these operators must be modified to use std :: min and std :: max instead.

  • It seems that there are 4.0.4 left .

+13
source

This is not C ++ code.

It uses the gnu extension and is not fully portable.

Just replace it with the standard code:

 if (d < somethingbigger) d = somethingbigger; 
+5
source

IIRC, this is a shorter version of d = max (d, somethingBigger); or

 d = (d < somethingbigger) ? somethingbigger : d; 

I have not seen this after some time, although I am sure that the GNU extension is for GCC.

0
source

All Articles