当前位置:网站首页>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
边栏推荐
- SPC introduction
- Log4j output log information to file
- Selenium IDE and XPath installation of chrome plug-in
- Dlib of face recognition framework
- 信息摘要、数字签名、数字证书、对称加密与非对称加密详解
- Website_ Collection
- Multithreaded @ async thread pool
- Use itextpdf to intercept the page to page of PDF document and divide it into pieces
- Modify the test case name generated by DDT
- SQL database
猜你喜欢
Quick install mongodb
如何建立 TikTok用户信任并拉动粉丝增长
英语 | Day15、16 x 句句真研每日一句(从句断开、修饰)
PyMySQL
TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
MySQL master-slave replication
详解牛客----手套
CentOS MySQL multi instance deployment
Derivation of Σ GL perspective projection matrix
Pycham connects to the remote server and realizes remote debugging
随机推荐
Talk about browser cache control
Installation and management procedures
org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
Tencent resolves the address according to the IP address
Easyexcel reads the geographical location data in the excel table and sorts them according to Chinese pinyin
Expression "func" tSource, object "to expression" func "tSource, object" []
◰ GL shadow map core steps
File upload and download of robot framework
Flask如何在内存中缓存数据?
PHP efficiently reads large files and processes data
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
How much do you know about the process of the interview
文件操作详解(2)
Camtasia2022软件新增功能介绍
Disk management and file system
Use case labeling mechanism of robot framework
vim编辑器的实时操作
Custom implementation of Baidu image recognition (instead of aipocr)
Knowledge points and examples of [seven input / output systems]
RAID磁盘阵列与RAID5的创建