传入类型:
#define min_t(type,x,y) \
({ \
type __x = (x); \
type __y = (y); \
__x < __y ? __x:__y;/* 结果返回 */ \
})
无传入类型:
#define min(x,y) \
({ \
const typeof(x) _x = (x); \
const typeof(y) _y = (y); \
(void) (&_x == &_y); /* 检查类型是否一致 */\
_x < _y ? _x : _y; /* 返回结果 */ \
})
函数名打印:
void test(){
printf("this is function:%s\n", __FUNCTION__);
}
/* 执行结果打印 this is function:test */
do{} while(0)语句宏:
#define SAFE_FREE(p) \
do{ \
if(p == NULL) break; \
free(p); \
p = NULL; \
}while(0)
goto语句: 主要应用场景 错误处理较为容易.