D
Dom Gilligan
Is there any way to get the preprocessor to produce the current line
number in double quotes? At first sight, gcc seems to replace __LINE__
last (which would make sense), and so won't replace it at all if it's
preceded by '#'.
Background: I want to produce a string giving the current file and
line number in an array of structures, as follows:
---------------
#define OP(z) OP2(__FILE__, __LINE__, z)
#define OP2(x,y,z) { x ", line " #y ": ", z }
struct opinfo {
const char *preamble;
const char *cstr;
};
....
opinfo ops[] = {
OP("wibble1"),
OP("wibble2")
};
---------------
My intention is that this should produce an array of two opinfos which
look like:
opinfo ops[] = {
{ "src.cc, line 10: ", "wibble1" },
{ "src.cc, line 11: ", "wibble2" }
};
However, what it actually produces is:
opinfo ops[] = {
{ "src.cc, line __LINE__: ", "wibble1" },
{ "src.cc, line __LINE__: ", "wibble2" }
};
Any ideas?
Thanks -
Dom
number in double quotes? At first sight, gcc seems to replace __LINE__
last (which would make sense), and so won't replace it at all if it's
preceded by '#'.
Background: I want to produce a string giving the current file and
line number in an array of structures, as follows:
---------------
#define OP(z) OP2(__FILE__, __LINE__, z)
#define OP2(x,y,z) { x ", line " #y ": ", z }
struct opinfo {
const char *preamble;
const char *cstr;
};
....
opinfo ops[] = {
OP("wibble1"),
OP("wibble2")
};
---------------
My intention is that this should produce an array of two opinfos which
look like:
opinfo ops[] = {
{ "src.cc, line 10: ", "wibble1" },
{ "src.cc, line 11: ", "wibble2" }
};
However, what it actually produces is:
opinfo ops[] = {
{ "src.cc, line __LINE__: ", "wibble1" },
{ "src.cc, line __LINE__: ", "wibble2" }
};
Any ideas?
Thanks -
Dom