Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird usage of conditional operator (>?=) [duplicate]

I was looking 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 can't compile this with a recent compiler.

like image 639
Jasper Avatar asked Dec 02 '22 01:12

Jasper


2 Answers

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

  • If the extension is not enabled, then you will not be able to use this feature.

  • As of 4.0.1:

    The G++ minimum and maximum operators (<? and >?) and their compound forms (<?=) and >?=) have been deprecated and will be removed in a future version. Code using these operators should be modified to use std::min and std::max instead.

  • It looks like they were gone by 4.0.4.

like image 88
Lightness Races in Orbit Avatar answered Dec 07 '22 23:12

Lightness Races in Orbit


That's not C++ code.

It's using a gnu-only extension, and is completely non-portable.

Just replace it with standard-compliant code:

if (d < somethingbigger) d = somethingbigger;
like image 42
Ben Voigt Avatar answered Dec 07 '22 23:12

Ben Voigt