C 扩展名:?运营商

发布于 2024-09-13 02:38:54 字数 269 浏览 2 评论 0 原文

我观察到 GCC 中有时存在 >? 运算符。我如何在 GCC 4.5 下使用这些?它们是否已被删除?如果是,何时删除?

Offset block_count = (cpfs->geo.block_size - block_offset) <? count;
cpfs.c:473: error: expected expression before ‘?’ token

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还不是爱你 2024-09-20 02:38:54

最近的手册

G++ 最小值和最大值运算符('' 和 '>?')及其复合形式('') 和 '>?=') 已被弃用,现已从 G++ 中删除。使用这些运算符的代码应修改为使用 std::minstd::max 代替。


快速搜索过去的文档似乎表明它们在 4.0 版本左右被删除(3.4.6 包含它们,4.0.4 不包含)。

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).

旧情别恋 2024-09-20 02:38:54

g++ 的早期版本(不是 C 编译器)使用这些运算符来提供最小值或最大值,但它们早已被弃用,取而代之的是 std: :minstd::max

基本上,它们等同于(但是没有ab进行双重评估的可能性):

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

就替换它们而言(并且你真的< em>应该替换它们),您可以使用类似:

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

或使用 std::min 的等效项。

我不太喜欢使用 C/C++“扩展”(尤其是那些已被弃用和/或删除的扩展),因为它们将我与该语言的特定实现联系起来。

在有完全足够的标准方法可用的情况下,您永远不应该使用非标准扩展。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文