条件运算符 (>?=) 的奇怪用法

2022-01-17 00:00:00 conditional compiler-construction c++

我正在查看一些代码并看到类似这样的内容:

I was looking at some code and saw something like this:

int d = 1;
int somethingbigger = 2;

d >?= somethingbigger;

cout << d << endl;

我认为这应该输出 2.但我什至不能用 gcc 4.5.2 编译它.该代码是在 2005 年编写的,并使用 gcc 3.4.4 编译(不是 100% 确定).

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.

推荐答案

这是最大"赋值运算符,一个 GCC 扩展.

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.

自 4.0.1 起:

G++ 最小和最大运算符(<?>?)及其复合形式 (<?=) 和 >?=) 已被弃用并将被在未来的版本中删除.使用这些运算符的代码应该是修改为使用 std::min 和 std::max 代替.

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.

  • 看起来 它们在 4.0.4 之前就消失了.

  • 相关文章