当前位置:网站首页>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[xm
Pairs 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 ,
stderr
Still output to the screen .
边栏推荐
猜你喜欢
My experience in functional testing for so many years
Pycharm shortcut key
原来你是这样的数组,终于学会了
File Transfer Protocol,FTP文件共享服务器
01. regular expression overview
深度学习---三好学生各成绩所占权重问题(3)
1.5 - logical operation
Detailed description of methods in the interface
基础刷题(一)
Analysis of startup process of gazebo multi computer simulation
随机推荐
ES6 arrow function
Base64 explanation: playing with pictures Base64 encoding
File operation io-part1
力扣------替换空格
Fastapi learning Day2
[my creation anniversary] one year anniversary essay
Never forget the original intention, and be lazy if you can: C # operate word files
How does Altium designer hide some temporarily unnecessary classes, such as GND
880. decoded string at index
1.6 - CPU组成
Thread safe solutions, communication between threads (classic examples of producers and consumers)
1.8 - multi level storage
c# - C#用fo-dicom对CT图像的PixelData进行处理和转换
File Transfer Protocol,FTP文件共享服务器
图片。。。。。
1.5 - 逻辑运算
Use and principle of completionservice (source code analysis)
Rhcsa day 3
As function memo
Image processing 7- image enhancement