抑郁症健康,内容丰富有趣,生活中的好帮手!
抑郁症健康 > c 语言 宏 可变 参数 C语言 如何在宏定义中使用可变参数

c 语言 宏 可变 参数 C语言 如何在宏定义中使用可变参数

时间:2021-08-19 22:50:09

相关推荐

有一个记录日志的函数,想用宏定义进行包装,简化调用方法,但是xlc报如下的错误:void _log(const int level, char* file, int line, const char* fmt, ...){

va_list ap;

int count;

time_t t;

struct tm* st;

char str_time[255];

memset(str_time, 0x00, sizeof(str_time));

time(&t);

st= localtime(&t);

switch(level){

case DEBUG:

fprintf(stdout, "[DEBUG] ");

break;

case INFO:

fprintf(stdout, "[INFO] ");

break;

case WARNING:

fprintf(stdout, "[WARNING] ");

break;

case ERROR:

fprintf(stdout, "[ERROR] ");

break;

default:

fprintf(stdout, "[INFO] ");

break;

}

strftime( str_time, sizeof(str_time), "%Y-%m-%d %H:%M:%S", st);

fprintf(stdout, "[%s] LINE:[%04d] [%s] ", file, line, str_time);

va_start(ap, fmt);

count = vfprintf(stdout, fmt, ap);

fprintf(stdout, "\n");

fflush(stdout);

va_end(ap);

}

#define log_info(...) _log((INFO), (__FILE__), (__LINE__), "", (#__VA_ARGS__))

#define log_err(...) _log((ERROR), (__FILE__), (__LINE__), "", (#__VA_ARGS__))Syntax error at line 71, column 18, file RProCrminfo.cp:

Error at line 71, column 18 in file RProCrminfo.cpdefine log\_info((aaa), ...) \_log((INFO), (\_\_FILE\_\_), (\_\_LINE\_\_), "", (#_\_VA\_ARG

S__))

.................1

PCC-S-0, Encountered the symbol "(" when expecting one of the following:

) ... an identifier, define, elif, else, endif, error, if,

ifdef, ifndef, include, line, pragma, undef, exec, sql,

begin, end, var, type, oracle,

an immediate preprocessor command, a C token, create,

function, package, procedure, trigger, or, replace,

The symbol ")" was substituted for "(" to continue.

如果觉得《c 语言 宏 可变 参数 C语言 如何在宏定义中使用可变参数》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。