为什么 TRACE() 抛出浮点数下溢异常?
Why TRACE() throws Floating-point underflow exception?
为什么在TRACE中会出现浮点数下溢(参数:0x00000000)?
我在这里需要什么格式说明符?
// show load progress by callback-Funktion (on Statusbar)
ULONGLONG len = 1000; // ar.GetFile()->GetLength();
ULONGLONG pos = 800; // ar.GetFile()->GetPosition();
double perc = (double)pos/(double)len*100;
TRACE("load from %X, Position: %ld, Length: %ld, Perc: %lf \n",
this, pos, len, perc );
更新
len
和 pos
不关心,TRACE
在 调试模式 中总是抛出一个错误。
使用使用多字节字符集 编译。将代码从 VS9 升级到 VS14。在 Release-Mode 下似乎一切正常。
调试输出为:
Natvis: Parsing natvis xml file: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers\windows.media.natvis.
Natvis: Parsing natvis xml file: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers\windows.natvis.
Natvis: Parsing natvis xml file: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers\winrt.natvis.
Natvis: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers\atlmfc.natvis(9,28): Successfully parsed expression 'm_hWnd' in type context 'CWnd'.
Exception thrown at 0x5B4EE469 (ucrtbased.dll) in TestProgD.exe: 0xC0000093: Floating-point underflow (parameters: 0x00000000).
Unhandled exception at 0x5B4EE469 (ucrtbased.dll) TestProgD.exe: 0xC0000093: Floating-point underflow (parameters: 0x00000000).
格式说明符与参数类型不匹配,因此您有未定义的行为。
%X
(unsigned int
)应该是%p
(指针)。
%ld
(long int
) 应该是 %llu
(unsigned long long
)。在 Windows 平台上 long int
与 int
相同,因此它始终是 32 位的,无论代码是为 32 位还是 64 位构建的。只有 long long
始终是 64 位。当然你也想匹配签名,这就是必须使用 u
说明符的原因。
为什么在TRACE中会出现浮点数下溢(参数:0x00000000)? 我在这里需要什么格式说明符?
// show load progress by callback-Funktion (on Statusbar)
ULONGLONG len = 1000; // ar.GetFile()->GetLength();
ULONGLONG pos = 800; // ar.GetFile()->GetPosition();
double perc = (double)pos/(double)len*100;
TRACE("load from %X, Position: %ld, Length: %ld, Perc: %lf \n",
this, pos, len, perc );
更新
len
和 pos
不关心,TRACE
在 调试模式 中总是抛出一个错误。
使用使用多字节字符集 编译。将代码从 VS9 升级到 VS14。在 Release-Mode 下似乎一切正常。
调试输出为:
Natvis: Parsing natvis xml file: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers\windows.media.natvis.
Natvis: Parsing natvis xml file: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers\windows.natvis.
Natvis: Parsing natvis xml file: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers\winrt.natvis.
Natvis: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers\atlmfc.natvis(9,28): Successfully parsed expression 'm_hWnd' in type context 'CWnd'.
Exception thrown at 0x5B4EE469 (ucrtbased.dll) in TestProgD.exe: 0xC0000093: Floating-point underflow (parameters: 0x00000000).
Unhandled exception at 0x5B4EE469 (ucrtbased.dll) TestProgD.exe: 0xC0000093: Floating-point underflow (parameters: 0x00000000).
格式说明符与参数类型不匹配,因此您有未定义的行为。
%X
(unsigned int
)应该是%p
(指针)。%ld
(long int
) 应该是%llu
(unsigned long long
)。在 Windows 平台上long int
与int
相同,因此它始终是 32 位的,无论代码是为 32 位还是 64 位构建的。只有long long
始终是 64 位。当然你也想匹配签名,这就是必须使用u
说明符的原因。