当前位置:网站首页>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 .
边栏推荐
- Force buckle ------ replace blank space
- ETL为什么经常变成ELT甚至LET?
- 0基础转行软件测试,如何实现月薪9.5k+
- Jgaurora A8 configuration file
- Deep learning --- the weight of the three good students' scores (3)
- As function memo
- Introduction to neural networks
- Fastapi learning Day1
- JS prototype chain object function relationship
- Set in set (III)
猜你喜欢
随机推荐
Idea add database
Use of observer mode and status mode in actual work
原理:WebMvcConfigurer 与 WebMvcConfigurationSupport避坑指南
1.7 - CPU performance indicators
Completabilefuture: from understanding to mastering, here are all you want to know
Getting started with research
1.2(补充)
Unable to read file for extraction: gdx64. dll
Altium designer creates multiple class networks to realize different lineweights of multiple networks
图解八股,真的太顶了
图片。。。。。
Inner member of class 5: inner class
Notes of the first week of 2021 Chengdu Arts and Sciences cloud computing intensive training class
INI analyse les documents d'apprentissage
Base64详解:玩转图片Base64编码
Rhcsa day 1
程序猿入门攻略(十一)——结构体
C language: exercise 3
Cocos studio3.1 installation package win
Simple example of class template