G
Generic Usenet Account
Can someone kindly explain why stringification of the compiler
preprocessor macro __LINE__ requires two steps, instead of one? I
wanted to pass the error location of a system call to perror() and I
found that I had to use a kludgy way to stick in the line number.
Thanks,
Song
///// Code Snippet /////
#include <stdio.h>
#include <errno.h>
#include <string>
using namespace std;
#define mkstr1(X) #X
#define mkstr2(X) mkstr1(X)
#define INVALID_FD 0x10000000
main()
{
int rc;
if((rc=read(INVALID_FD, NULL, 0)) < 0)
{
string errLoc = string(__FILE__) + string(", ") +
string(mkstr2(__LINE__));
perror(errLoc.c_str());
}
}
preprocessor macro __LINE__ requires two steps, instead of one? I
wanted to pass the error location of a system call to perror() and I
found that I had to use a kludgy way to stick in the line number.
Thanks,
Song
///// Code Snippet /////
#include <stdio.h>
#include <errno.h>
#include <string>
using namespace std;
#define mkstr1(X) #X
#define mkstr2(X) mkstr1(X)
#define INVALID_FD 0x10000000
main()
{
int rc;
if((rc=read(INVALID_FD, NULL, 0)) < 0)
{
string errLoc = string(__FILE__) + string(", ") +
string(mkstr2(__LINE__));
perror(errLoc.c_str());
}
}