当前位置:网站首页>Variable length parameter__ VA_ ARGS__ Macro definitions for and logging
Variable length parameter__ VA_ ARGS__ Macro definitions for and logging
2022-04-23 16:54:00 【The interview was rejected 10000 times】
Variable length parameter __VA_ARGS__ and Macro definition for logging
Macro definition with ’#' Different meanings of characters
With a ‘#’ Convert to string
#define _TOSTRING(x) #x
int main()
{
auto s1 = _TOSTRING(123);
std::cout << " s1 " <<s1 <<std::endl; // "123" return const char*
}
Take two “##” It's splicing ( Mainly with ##__VA_ARGS__ Together with )
Replacement part for macro , This operator combines two language symbols into a single language symbol , It provides a means for macro extension to connect actual arguments . It can also be used as digital splicing ,
But be careful int Value range of , I use this macro to replace ( Connect two strings ) Will report a mistake , Is the wrong parameter , As for why to return int, I don't understand yet , If anyone knows, Sue
Tell me
#define CONNECT_TWO(x,y) x##y
int main()
{
auto s2 = CONNT_TWO(123,456);
std::cout << " s2 " <<s2 <<std::endl; // Back to a int Digital splicing of ,123456
}
Define log macros
The first one is : Log macro , Be careful. : stay define If it is a multi line definition , You need to add a symbol '\'
#define LOG(...){ \
fprintf(stderr,"File:%s Line:%d Func:%s \t",__FILE__,__LINE__,__func__ );\
fprintf(stderr,__VA_ARGS__);\
fprintf(stderr,"\n");\
}
The second kind : Let's first understand Predefined macros VA_ARGS
// Predefined macros __VA_ARGS__ You can replace the string represented by the ellipsis in the implementation part of the macro definition
// In the macro definition Use __VA_ARGS__ Replace ...
#define myPrintf(...) printf(__VA_ARGS__)
In the use of c++ When compiling, you should pay attention to , When connecting variables and strings, you need to add spaces , So the following is fmt There are spaces left and right
#define error_printf(fmt,...) printf("[ERROR][%s]( %s | %d )" fmt "\n",__FILE__,__FUNCTION__,__LINE__,##__VA_ARGS__)
above Macro definition Can be used as a variable
__FILE__ : The file name is returned
__LINE__ : It returns the number of rows
__FUNCTION__ : The function name is returned
The above is some understanding of my own integration , Refer to the blog address :
Add link description
版权声明
本文为[The interview was rejected 10000 times]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231359046474.html
边栏推荐
- 无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
- Calculation formula related to tolerance analysis
- RTKLIB 2.4.3源码笔记
- 【PIMF】OpenHarmony啃论文俱乐部—在ACM Survey闲逛是什么体验
- Pycham connects to the remote server and realizes remote debugging
- Generate random numbers with high quality and Gaussian distribution
- Get the column name list of the table quickly in Oracle
- 1959年高考数学真题
- Introduction to how to set up LAN
- New project of OMNeT learning
猜你喜欢
Set the color change of interlaced lines in cells in the sail software and the font becomes larger and red when the number is greater than 100
无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
Disk management and file system
PyTorch:train模式与eval模式的那些坑
Derivation of Σ GL perspective projection matrix
loggie 源码分析 source file 模块主干分析
Project framework of robot framework
∑GL-透视投影矩阵的推导
VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN
Zhongang Mining: Fluorite Flotation Process
随机推荐
Blue Bridge Cup provincial road 06 -- the second game of the 12th provincial competition
STM32__03—初识定时器
∑GL-透视投影矩阵的推导
Custom implementation of Baidu image recognition (instead of aipocr)
Paging the list collection
Selenium IDE and XPath installation of chrome plug-in
MySQL master-slave synchronization pit avoidance version tutorial
文件操作详解(2)
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
深入了解3D模型相关知识(建模、材质贴图、UV、法线),置换贴图、凹凸贴图与法线贴图的区别
TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
计算饼状图百分比
Easyexcel reads the geographical location data in the excel table and sorts them according to Chinese pinyin
Talk about browser cache control
feign报400处理
Set cell filling and ranking method according to the size of the value in the soft report
无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
英语 | Day15、16 x 句句真研每日一句(从句断开、修饰)
Solution of garbled code on idea console
Rtklib 2.4.3 source code Notes