VC ++签名和未签名的问题__int64<<和>>运营商? [英] Problem with VC++ signed and unsigned __int64 << and >> operators?
问题描述
以下代码段似乎无法正常工作
unsigned __int64 result = 0xFFFFFFFFFFFFFFFF;
result = result<< 64;
Debugger.WriteLine(System :: String :: Format(S" {0:X16}",__ box(result));
result = 0xFFFFFFFFFFFFFFFF;
result = result>> 64;
Debugger.WriteLine(System :: String :: Format(S" {0:X16}",__ box(结果) ));
__int64结果= -1;
结果=结果<< 64;
Debugger.WriteLine( System :: String :: Format(S" {0:X16}",__ box(result));
我期待输出读取
0000000000000000
FFFFFFFFFFFFFFFF
0000000000000000
FFFFFFFFFFFFFFFF
但输出读数
FFFFFFFF00000000<<不正确
00000000FFFFFFFF<<不正确
FFFFFFFF00000000<<不正确
FFFFFFFFFFFFFFFF<<正确
所有其他班次值(< 64)似乎都能正常工作。
来自MS的人可以确认这是int64 shift的错误
运营商,好吗?
彼得
-
如果你想回复直接我,我的地址是垃圾邮件证明:
pbromley at adi dot co nz
或者如果您愿意 - 没有**** @ nowhere.com :-)
The following code snippet does not seem to work correcly
unsigned __int64 result = 0xFFFFFFFFFFFFFFFF;
result = result << 64;
Debugger.WriteLine(System::String::Format(S"{0:X16 }", __box(result));
result = 0xFFFFFFFFFFFFFFFF;
result = result >> 64;
Debugger.WriteLine(System::String::Format(S"{0:X16 }", __box(result));
__int64 result = -1;
result = result << 64;
Debugger.WriteLine(System::String::Format(S"{0:X16 }", __box(result));
I am expecting output to read
0000000000000000
FFFFFFFFFFFFFFFF
0000000000000000
FFFFFFFFFFFFFFFF
but output reads
FFFFFFFF00000000 << incorrect
00000000FFFFFFFF << incorrect
FFFFFFFF00000000 << incorrect
FFFFFFFFFFFFFFFF << correct
All other shift values ( < 64) appear to work correctly.
Can someone from MS confirm this is a bug with the int64 shift
operators, please?
Peter
--
If you wish to reply to me directly, my addres is spam proofed as:
pbromley at adi dot co dot nz
Or if you prefer - no****@nowhere.com :-)
推荐答案
Peter Bromley写道:
Peter Bromley wrote:
以下代码片段似乎无法正常工作
unsigned __int64 result = 0xFFFFFFFFFFFFFFFF;
结果=结果<< 64;
Debugger.WriteLine(System :: String :: Format(S" {0:X1 6}",__ box(result));
result = 0xFFFFFFFFFFFFFFFF;
result = result >> 64;
Debugger.WriteLine(System :: String :: Format(S" {0:X1 6}",__ box(result));
__ int64 result = -1;
结果=结果<< 64;
Debugger.WriteLine(System :: String :: Format(S" {0:X1 6}",__ box(result));
我期待输出阅读
0000000000000000
FFFFFFFFFFFFFFFF
0000000000000000
FFFFFFFFFFFFFFF
但输出读取
FFFFFFFF00000000<<不正确
00000000FFFFFFFF<<错误
FFFFFFFF00000000<<不正确
FFFFFFFFFFFFFFFF<<正确
所有其他移位值(< 64)似乎都能正常工作。
The following code snippet does not seem to work correcly
unsigned __int64 result = 0xFFFFFFFFFFFFFFFF;
result = result << 64;
Debugger.WriteLine(System::String::Format(S"{0:X1 6}", __box(result));
result = 0xFFFFFFFFFFFFFFFF;
result = result >> 64;
Debugger.WriteLine(System::String::Format(S"{0:X1 6}", __box(result));
__int64 result = -1;
result = result << 64;
Debugger.WriteLine(System::String::Format(S"{0:X1 6}", __box(result));
I am expecting output to read
0000000000000000
FFFFFFFFFFFFFFFF
0000000000000000
FFFFFFFFFFFFFFFF
but output reads
FFFFFFFF00000000 << incorrect
00000000FFFFFFFF << incorrect
FFFFFFFF00000000 << incorrect
FFFFFFFFFFFFFFFF << correct
All other shift values ( < 64) appear to work correctly.
将值移动一个> =其长度(以位为单位)是未定义的,所以你
需要避免这样做。
-
Doug Harrison
Microsoft MVP - Visual C ++
It''s undefined to shift a value by an amount >= its length in bits, so you
need to avoid doing that.
--
Doug Harrison
Microsoft MVP - Visual C++
>将值移动一个> =以位为单位的长度是未定义的,所以你
> It''s undefined to shift a value by an amount >= its length in bits, so you
需要避免这样做。
这只通过mc ++,对吧?在x86中的移位是明确定义的,因为
无符号0被移入,对于签名,符号位在需要时被扩展。
我想知道为什么同样的原因是什么为.net编译的代码
不应该给它与原生对应的结果相同。
This thru for mc++ only, right? Shifting in x86 is well defined, for
unsigned 0s are shifted in, for signed the sign bit is extended when needed.
I wonder what can be the reason why the same code compiled for .net
shouldn''t give the same results as its native counterpart.
" ; Gabest的" < GA **** @ freemail.hu>在消息中写道
news:e6 ************** @ TK2MSFTNGP14.phx.gbl ...
"Gabest" <ga****@freemail.hu> wrote in message
news:e6**************@TK2MSFTNGP14.phx.gbl...
将值移动一个> =它的长度(以位为单位)是未定义的,所以
你需要避免这样做。
It''s undefined to shift a value by an amount >= its length in bits, so
you
need to avoid doing that.
>这通过
"是真的我的意思是。这里真的很晚了:)
"is true" I mean. It''s really late here :)
这篇关于VC ++签名和未签名的问题__int64<<和>>运营商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!