调试技巧 ------ printf 的使用技巧

使用了可变参数的宏定义 

编译器宏:__FUNCTION__,__FILE__,__LINE__

#define __debug

#ifdef __debug
  //#define debug(format,...) printf("File: "__FILE__"
Line: %05d
message: "format"
", __LINE__, ##__VA_ARGS__)
  #define debug(format,...) printf("message: "format"
", ##__VA_ARGS__)
#else
  #define debug(format,...)
#endif

最近由于希望使用IAR的printf()函数方便进行打印字符,出现IAR报错,即:identifier "FILE" is undefined,问题得以解决。

  (1)进行printf到串口的重映射:

  需添加头文件:#include "stdio.h"

  

 (2)经编译出现:

  

 

 (3)经查找原来是这里需要进行配置:

 

 (4)改成full就可以了:

 

原文地址:https://www.cnblogs.com/god-of-death/p/8797592.html