代码用g ++编译而不是gcc [英] code compiles with g++ but not gcc

查看:208
本文介绍了代码用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)
是一个构造函数,但这让我想知道为什么它包含在代码中。是否有必要?

I would assume that in C++, int(f >> 31) is a constructor but that leaves me wondering why its 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天全站免登陆