为什么此代码使用g ++而不是gcc进行编译? [英] Why does this code compile with g++ but not gcc?

查看:71
本文介绍了为什么此代码使用g ++而不是gcc进行编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码使用g ++而不是gcc进行编译,并且困惑于为什么?

The following piece of code compiles with g++ and not gcc, and am stuck wondering why?

inline unsigned FloatFlip(unsigned f)
{
    unsigned mask = -int(f >> 31) | 0x80000000;
    return f ^ mask;
}

我认为在C ++中,

int(f >> 31)

是一个构造函数,但是让我想知道为什么它包含在代码中。

is a constructor but that leaves me wondering why it's included in the code. Is it necessary?

推荐答案

C不支持 C ++函数式强制转换。您需要这样写:

C doesn't support the C++ "function-style" casting. You need to write it like this

unsigned mask = -(int)(f >> 31) | 0x80000000;

请参见广播运算符

这篇关于为什么此代码使用g ++而不是gcc进行编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆