为什么在 TRACE 中会出现 float 下溢(参数: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
在Debug-Mode 中总是抛出错误。
使用使用多字节字符集 编译。将代码从 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
说明符的原因。
关于c++ - 为什么 TRACE() 抛出 float 下溢异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48705742/