当前位置:网站首页>Rising posture series: fancy debugging information
Rising posture series: fancy debugging information
2022-06-30 06:39:00 【Mnnk】
#include <stdio.h>
#define logD(fmt, ...) \ fprintf(stdout, "[\e[34m debug \e[0m] %s:%02d --> ", __FILE__, __LINE__); fprintf(stdout, fmt, ##__VA_ARGS__);
#define logE(fmt, ...) \ fprintf(stderr, "[\e[31m error \e[0m] %s:%02d --> ", __FILE__, __LINE__); fprintf(stderr, fmt, ##__VA_ARGS__);
int main(){
logD("%s\n", "here is debugging information");
logE("%s %d %s\n", "error info", 123, "args");
logD(" If not ##, This line compiles but ~\n");
return 0;
}
effect :
explain :
Reference resources : Erode yesterday
- #, Convert parameters to strings
#define P(x) printf("%s:%d\n",#x,x);
int a = 1, b = 2;
p(a + b); // Output :a + b:3
- ##, Used to connect symbols
#define XNAME(n) x##n
int x3 = 3;
cout << XNAME(3); // Output :3
P(XNAME(3)); // Output :XNAME(3):3
- __VA_ARGS__, yes C99 Macros with standard variable parameters , Equivalent to ellipsis in variable parameter function .
- ##__VA_ARGS__ , If not add ##, When the variable parameter is 0 when , A comma is added to the Hongzhan meeting , Causes compilation errors ,## To solve this problem .
- __FILE__, When the macro is expanded, it will be replaced with the current file name .
- __LINE__, When the macro is expanded, it will be replaced with the current line number .
- Terminal color code ,
\e[30m Content \e[0m,\e[xmPairs appear , The first number indicates the color , The ending number indicates the display effect .
Color :

According to the effect :
0 No effect 1 bold 4 Underline 5 flashing 7 reverse 8 hide - stdout, stderr, During terminal redirection ,
stderrStill output to the screen .
边栏推荐
- Cocos studio3.1 installation package win
- KEIL - 下载调试出现“TRACE HW not present”
- MySQL中的InnoDB引擎
- Unclear about glide loading picture
- 华泰炒股安全吗?我想网上开户。
- Improve simulation speed during ROS and Px4 joint simulation
- The 40g high-efficiency cloud disk purchased by Alibaba cloud is only 20g attached
- A complete performance test process
- 基础刷题(一)
- File Transfer Protocol,FTP文件共享服务器
猜你喜欢
随机推荐
Dynamic routing job
Four ways to create multithreads
Verilog中case,casez,casex语句的用法
Unable to access the Internet at win10 /11 hotspot
A complete performance test process
Huawei full-scale Daniel shared the 598 page full-color Manual of network protocols for the first time
ES6 extended operator (...)
原来你是这样的数组,终于学会了
Thread safe solutions, communication between threads (classic examples of producers and consumers)
Jgaurora A8 configuration file
Force buckle ------ replace blank space
File transfer protocol, FTP file sharing server
Arrangement of in-depth learning materials
C language: exercise 3
2020-10-06
Spin official tutorial
华泰炒股安全吗?我想网上开户。
Switch must be better than if Else fast
File Transfer Protocol,FTP文件共享服务器
Notes: environment variables









