I am trying to understand implement a print once function, this code is working fine; But I am not able to understand some things: 1) How blockwise this is working? Maybe I am not able to clear it properly, but just want to know, what property of C make this happen?
1 #include <stdio.h>
2
3 #define _TRACE_
4
5 #ifdef _TRACE_
6 #define print_once(fmt, ...) \
7 ({ \
8 static bool __print_once=false; \
9 if(!__print_once) { \
10 __print_once = true; \
11 do { \
12 printf(fmt, ##__VA_ARGS__); \
13 }while(0); \
14 } \
15 })
16 #else
17 #define print_once(fmt, ...) \
18 printf("\n");
19 #endif
20
21 void func()
22 {
23 print_once("func\n");
24 }
25 int main(int argc, char* argv[])
26 {
27 print_once("test1\n");
28 //:w
29 print_once("test22\n");
30 for(int i =0; i < 2; i++)
31 print_once("loop\n");
32 func();
33 func();
34 return 0;
35 }