当前位置:网站首页>Built-in macros in C language (define log macros)

Built-in macros in C language (define log macros)

2022-08-09 06:32:00 qq_36412526

When we write C language programs, we often use macro definitions. C language also has many built-in macros.
Powerful built-in macros:
built-in macros
Let's write a program that defines a log macro to get a feel for it.

#include #define LOG(s) do { \ printfspan>("%s %s [%s:%d] %s\n", __DATE__,__TIME__,__FILE__,__LINE__,s);\ }while(0)void f(){LOG("Enter f()...");LOG("Exit f()...");}int main(){LOG("Enter main()...");f();LOG("Exit main()...");return 0;}

Run it to see the effect:
Insert image description here
See it runAs a result, doesn't it feel very familiar? Isn't the compilation information of the compilers we use like this?When writing code in the future, it is very convenient to write log information or debug in this way.

原网站

版权声明
本文为[qq_36412526]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208090628552959.html