c语言浮点型右移运算符,我想输出float类型值的二进制位,位移运算符不行啊!

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

嗯嗯,翻了C99标准大概如下:

6.5 Expressions

7 An object shall have its stored value accessed only by an lvalue expression that has one of the following types:73)

— a type compatible with the effective type of the object,

— a qualified version of a type compatible with the effective type of the object,

— a type that is the signed or unsigned type corresponding to the effective type of the

object,

— a type that is the signed or unsigned type corresponding to a qualified version of the

effective type of the object,

— an aggregate or union type that includes one of the aforementioned types among its

members (including, recursively, a member of a subaggregate or contained union), or

— a character type.

Undefined behavior也有:

— An object has its stored value accessed other than by an lvalue of an allowable type

(6.5).

不过我还是对object所指存疑,即使以blog所给例子来看,稍微修改如下:

#include

int a;

int f(float *b)

{

a = 1;

*(int*)(b) = 0;

return a;

}

int g(float *b)

{

a = 1

*b = 0;

return a;

}

int main()

{

printf("%d\n", f((float*)&a));

printf("%d\n", g((float*)&a));

return 0;

}

gcc -O3结果是

0

1

关于这条我一般都是在别名的时候才会注意到,这种类型转换还真没注意= =;等我在去理解下……

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值