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

有一个记录日志的函数,想用宏定义进行包装,简化调用方法,但是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-02014, 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值