#define AT __FILE__ ":" TOSTRING(__LINE__)

#define AT __FILE__ ":" TOSTRING(__LINE__)

有时候为了增加调试程序信息具体,加上:
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define AT __FILE__ ":" TOSTRING(__LINE__)

example.c:
#include <stdio.h>
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define AT __FILE__ ":" TOSTRING(__LINE__)
void error(const char *location, const char *msg)
{
  printf("Error at %s: %s\n", location, msg);
}
int main(int , char**)
{
  error(AT, "fake error");
  return 0;
}

运行结果:
$./example
Error at example.c:12: fake error

你可能感兴趣的:(#define AT __FILE__ ":" TOSTRING(__LINE__))