获取代码行与__LINE__ [英] get code line with __LINE__
本文介绍了获取代码行与__LINE__的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用以下命令打印当前代码的行号:
I tried to print the line number of the current code by using:
#include <stdio.h>
void err (char *msg)
{
printf ("%s : %d" , msg , __LINE__);
}
int main ( int argc , char **argv )
{
ERR ("fail..");
return 0;
}
但我总是得到错误的行号,应该是 10
而不是 5
,我该如何解决这个问题?
But i always get the wrong line number , it should be 10
instead of 5
, how can i fix this ?
尝试使用一些宏:
#define ERR(msg)do {printf(%s:%d \\\
,msg, __线__); } while(0)
并导致错误: msg未声明
p>
and result in error: msg not declared
推荐答案
#define ERR(msg) printf("%s : %d", (msg), __LINE__)
应该做的。
您不需要该功能!
这篇关于获取代码行与__LINE__的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文