当前位置:网站首页>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 .
边栏推荐
- Verilog中case,casez,casex语句的用法
- Practice summary of Prometheus project in amu Laboratory
- 原理:WebMvcConfigurer 与 WebMvcConfigurationSupport避坑指南
- C language: exercise 3
- 583. deleting two strings - Dynamic Planning
- Rhcsa day 1
- Decompilation normal decompilation problems. Solve them yourself
- c# - C#用fo-dicom对CT图像的PixelData进行处理和转换
- Control method of UAV formation
- 不忘初心,能偷懒就偷懒:C#操作Word文件
猜你喜欢

Judge whether H5 is in wechat environment or enterprise wechat environment at both ends

1.8 - 多级存储

Dynamic routing job

Use and principle of completionservice (source code analysis)

Gazebo model modification

RT thread Kernel Implementation (I): threads and scheduling

0基础转行软件测试,如何实现月薪9.5k+

1.9 - Classification of memory

01. 正则表达式概述

1.7 - CPU的性能指标
随机推荐
Spin official tutorial
1.8 - multi level storage
Thread safe solutions, communication between threads (classic examples of producers and consumers)
Initial love with mqtt
Unable to access the Internet at win10 /11 hotspot
c# - C#用fo-dicom对CT图像的PixelData进行处理和转换
IO stream (file class introduction)
判断h5在两端是在微信环境还是企业微信环境
Pycharm shortcut key
圖像處理7-圖像增强
Joseph problem C language
A complete performance test process
Introduction to neural networks
Installation and initialization of MariaDB database
从底层结构开始学习FPGA----RAM IP核及关键参数介绍
[untitled]
Rhcsa day 3
1.6 - CPU composition
1.3 - Code System
01. regular expression overview