获得与__LINE__ code线 [英] get code line with __LINE__

查看:91
本文介绍了获得与__LINE__ code线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用可打印当前code的行号:

 的#include<&stdio.h中GT;无效ERR(字符* MSG)
{
    的printf(%S:%D,味精,__LINE__);
}INT主(INT ARGC,字符** argv的)
{
    ERR(失败..);
    返回0;
}

但我总是得到错误的行号,它应该是 10 而不是 5 的,我该怎么修复此?

此外,我试图用一些宏:

的#define ERR(MSG){做的printf(%S:%d个\\ N,味精,__LINE__); }而(0)

和导致错误:信息不声明


解决方案

 的#define ERR(MSG)的printf(%S:%D(MSG),__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;
}

But i always get the wrong line number , it should be 10 instead of 5 , how can i fix this ?

Also i tried to use some macro:

#define ERR (msg) do { printf ("%s : %d\n" , msg , __LINE__); } while (0)

and result in error: msg not declared

解决方案

#define ERR(msg) printf("%s : %d", (msg), __LINE__)

Should do the trick.

You do not need the function!

这篇关于获得与__LINE__ code线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆