为什么TRACE()会引发浮点下溢异常? [英] Why TRACE() throws Floating-point underflow exception?

查看:139
本文介绍了为什么TRACE()会引发浮点下溢异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在TRACE中出现浮点下溢(参数:0x00000000)? 我在这里需要什么格式说明符?

Why do I get a Floating-point underflow (parameters: 0x00000000) in TRACE? What format specifier do I need here?

// 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 ); 

更新

lenpos无关紧要,TRACE Debug-Mode (调试模式)中始终抛出错误. 与使用多字节字符集一起编译.将代码从VS9升级到VS14.在发布模式中,一切正常.

Update

The len and pos does not care, TRACE throws always an Error in Debug-Mode. Compiled with Use Multi-Byte Character Set. Upgraded the code from VS9 to VS14. In Release-Mode it seems working all fine.

调试输出为:

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).

推荐答案

格式说明符与参数类型不匹配,因此您具有不确定的行为.

The format specifiers do not match the argument types, so you have undefined behaviour.

  • %X(unsigned int)应该是%p(指针).
  • %ld(long int)应该是%llu(unsigned long long).在Windows平台上,long intint相同,因此,无论代码是针对32位还是64位构建的,它始终为32位.只有long long始终为64位.当然,您还希望匹配签名,这就是为什么必须使用u说明符的原因.
  • %X (unsigned int) should be %p (pointer).
  • %ld (long int) should be %llu (unsigned long long). On the Windows platform long int is the same as int, so it is always 32-bit, regardless whether the code is built for 32-bit or 64-bit. Only long long is always 64-bit. Of course you also want to match the signedness, that's why the u specifier must be used.

参考.

这篇关于为什么TRACE()会引发浮点下溢异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆