一个assert的写法

 1 char assert_buf[512];
 2 int assert_buf_len;
 3 
 4 #ifdef XXX_DEBUG
 5 #define assert(expr, ...) 
 6 do{    
 7     if ((!(expr))) 
 8     {
 9         char *str = __FILE__; 
10         int i; 
11         for(i=strlen(str);i>=0;i--) if(str[i]=='\'||str[i]=='/') break; 
12         printf("ASSERTION FAILED (%s) at: %s:%d:: ", #expr, str+i+1, __LINE__);
13         assert_buf_len = snprintf(assert_buf, sizeof(assert_buf)-1, __VA_ARGS__);
14         printf("%s
", assert_buf);
15     }
16 } while (0)
17 #else
18 #define assert(expr, ...) do{ 
19 }while(0)
20 #endif
原文地址:https://www.cnblogs.com/utank/p/5750563.html