Skip to content

Instantly share code, notes, and snippets.

@simonliu009
Last active January 7, 2019 14:01
Show Gist options
  • Save simonliu009/86f863fcd775b6e78cd0c07ecd3cec8a to your computer and use it in GitHub Desktop.
Save simonliu009/86f863fcd775b6e78cd0c07ecd3cec8a to your computer and use it in GitHub Desktop.
debug: debug output macro, STM, debug宏定义,可以一次性开启或者关闭DEBUG信息 #STM #debug
#define __DEBUG__
#ifdef __DEBUG__
#define DEBUG(format,...) printf("File: "__FILE__", Line: %05d: "format"/n", __LINE__, ##__VA_ARGS__)
#else
#define DEBUG(format,...)
#endif
以上在STM32 System Workbench 编译通过,但是在Xcode 9.3 (Apple LLVM version 9.1.0 (clang-902.0.39.1))编译会提示错误:
Invalid suffix on literal; C++11 requires a space between literal and identifier
Fix insert" "
No matching literal operator for call to 'operator""__FILE__' with arguments of types 'const char *' and 'unsigned long', and no matching literal operator template
需要在format前面和__File__前后都添加空格,修改成
#define __DEBUG__
#ifdef __DEBUG__
#define DEBUG(format,...) printf("File: " __FILE__ ", Line: %05d: " format "/n", __LINE__, ##__VA_ARGS__)
#else
#define DEBUG(format,...)
#endif
但是还是会有提示
'DEBUG' macro redefined
把DEBUG替换成 Mylog 就好了
#define __Mylog__
#ifdef __Mylog__
#define Mylog(format,...) printf("File: " __FILE__ ", Line: %05d: " format"/n", __LINE__, ##__VA_ARGS__)
#else
#define Mylog(format,...)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment