当前位置:网站首页>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
边栏推荐
- Installation and management procedures
- Node access to Alipay open platform sandbox to achieve payment function
- Feign report 400 processing
- 1959年高考数学真题
- JMeter installation tutorial and solutions to the problems I encountered
- UWA Pipeline 功能详解|可视化配置自动测试
- 5分钟NLP:Text-To-Text Transfer Transformer (T5)统一的文本到文本任务模型
- 文件操作详解(2)
- Take according to the actual situation, classify and summarize once every three levels, and see the figure to know the demand
- Creation of RAID disk array and RAID5
猜你喜欢
详解牛客----手套
PyMySQL
NVIDIA graphics card driver error
Modify the test case name generated by DDT
昆腾全双工数字无线收发芯片KT1605/KT1606/KT1607/KT1608适用对讲机方案
Node access to Alipay open platform sandbox to achieve payment function
1959年高考数学真题
Derivation of Σ GL perspective projection matrix
英语 | Day15、16 x 句句真研每日一句(从句断开、修饰)
VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN
随机推荐
Zhongang Mining: Fluorite Flotation Process
SPC introduction
DanceNN:字节自研千亿级规模文件元数据存储系统概述
Flask如何在内存中缓存数据?
伪分布安装spark
RAID磁盘阵列与RAID5的创建
MySQL master-slave synchronization pit avoidance version tutorial
Rtklib 2.4.3 source code Notes
Introduction to how to set up LAN
Generate random numbers with high quality and Gaussian distribution
Node access to Alipay open platform sandbox to achieve payment function
昆腾全双工数字无线收发芯片KT1605/KT1606/KT1607/KT1608适用对讲机方案
英语 | Day15、16 x 句句真研每日一句(从句断开、修饰)
Bytevcharts visual chart library, I have everything you want
Shell脚本——Shell编程规范及变量
5分钟NLP:Text-To-Text Transfer Transformer (T5)统一的文本到文本任务模型
如何建立 TikTok用户信任并拉动粉丝增长
UWA Pipeline 功能详解|可视化配置自动测试
org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
Website_ Collection