ARM-GCC下sprintf()的BUG?

ADL User Guide for Open AT. OS v6.1

    今天在调试程序时,发现了ARM-GCCsprintf()的一个问题,它不支持浮点数。以前从来没碰到这个问题,而且认为这肯定不会有问题,折腾了半天,最后在ADL_User_Guide中找到了答案。ARM-GCC下的sprintf()确实不支持%f,文档中给出了相应的解决方法。

     Important remark about GCC compiler:

When using GCC compiler, due to internal standard C library architecture, it is strongly not recommended to use the "%f" mode in the wm_sprintf function in order to convert a float variable to a string. This leads to an ARM exception (product reset).

A way around for this conversion is:

float MyFloat; // float to display

ascii MyString [ 100 ]; // destination string

s16 d,f;

d = (s16) MyFloat * 1000; // Decimal precision: 3 digits

f = ( MyFLoat * 1000 ) - d; // Decimal precision: 3 digits

                  wm_sprintf ( MyString, "%d.%03d", (s16)MyFloat, f ); // Decimal precision: 3 digits

    实践证明,经验主义要不得,看文档很重要,而且要看仔细。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值