定义一个打印函数错误的宏
#define CHECK_FUNC_RET(func) \
do { int err_code = E_PROP_UNKNOWN; \
if ((err_code = (func)) != E_PROP_OK) { \
PrintError(err_code, __FUNCTION__, __LINE__); return err_code; } \
} while(0)
void PrintError(int err_code, const char* func, int line)
{
struct
{
int err_code;
const char* err_name;
}
err_name_table[] = {
{ E_UNKNOWN, "E_UNKNOWN" },
};
const char* err_name = NULL;
for (unsigned int i = 0 ; i < sizeof(err_name_table) / sizeof(err_name_table[0]); ++i)
{
if (err_code == err_name_table[i].err_code)
{
err_name = err_name_table[i].err_name;
break;
}
}
if (err_name != NULL)
fprintf(stderr, "Function check failed. %s:%d - %s\n", func, line, err_name);
else
fprintf(stderr, "Function check failed. %s:%d - %d\n", func, line, err_code);
}
阅读(1231) | 评论(0) | 转发(0) |