printf() 与 RETAILMSG() 差别

 

转自:http://blog.chinaunix.net/u2/74100/showart_1154283.html 

 

printf() 与 RETAILMSG() 差别

 
   这个printf(),大家可能都是很熟悉的了,而 RETAILMSG()是在evc 下的嵌入式开发 s3c2410,arm9 ,用的,在wince 操作系统下的。
  大家在调试信息的时候,一般都会用到这些函数,来显示输出信息;evc 对两个函数也都是支持的。
  但是,如果系统对实时性要求高的话,那么这两个函数就会有很大的区别;
  printf 函数的所使用的时间要远比RETAILMSG()大的多。printf函数的调用大约要用去100毫秒的时间,而RETAILMSG()用的时间大约10毫秒;
  所以在,debug 版本的调试中,在输出信息的地方,能用RETAILMSG()就用RETAILMSG();尽量不用printf;
  当然在,realease 版本中,要把所有的输出调试信息的函数尽量都屏蔽掉;方法是通过使用 #ifdef ,如下:
#ifdef DEBUG
  printf("/n broadcast Hello");
#endif;
【or】
#ifdef DEBUG
  RETAILMSG(1,(TEXT("Receive a packet/t/n")));
#endif;
那么,在debug的版本中,为什么printf函数和RETAILMSG()会有这么大的时间差别呢??
  这个问题待研究???????
  补充:来自MSDN

RETAILMSG
 

This macro conditionally outputs a printf-style formatted message.

 

RETAILMSG (
   Expression,
   Message
)

第一个参数是bool型,判断是否有效,1有效;第二个参数是相关答应消息!

Parameters
Expression
Boolean expression used to determine if the message would be output.
Message
Expression to be printed using printf format style.
Return Values

None.

Remarks

The printf-style message parameter is output if the Boolean input expression evaluates to TRUE. Note that the parameter Message must be enclosed by parentheses to prevent syntax errors being generated by the preprocessor. This macro should be used sparingly, as it increases the size of retail builds.

Example
RETAILMSG(TRUE, (TEXT("Testing item count against maximum %u/r/n"),
         dwMaxNumberOfItems));
RETAILMSG(dwCurrentNumberOfItems >= dwMaxNumberOfItems,
          (TEXT("Invalid item count! Found %u, expected less than %u/r/n"),
           dwCurrentNumberOfItems, dwMaxNumberOfItems));

Output:

   

     Testing item count against maximum 68
 Invalid item count! Found 343, expected less than 68

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值