C
Chris
Hello all,
Using g++ 3.3.1 on Linux ("Linux From Scratch") I have a data
structure SCSIParams_t that I wish to print out, field-by-field.
Rather than code a long line of the form
std::cout << "fieldname = " << basepointer->fieldname <<
std::endl;
for every field, I'd like to do it with a short macro, e.g.
EMITSCSI(SCSIDriverType);
I've coded a macro definition
#define EMITSCSI(fieldname) \
std::cout << # field << " = " << basepointer->##fieldname <<
std::endl
and coded, as a test, a single line identical to the "short macro,
e.g..." example shown above.
That line generates the compile error,
pasting "->" and "fieldname" does not give a valid
preprocessing token
However, using the -E switch on the compile line, I find that the
macro does, in fact, expand to a line identical to the "long line..."
shown above. In fact, if I cut-and-paste the expansion text from the
preprocessor output into my source file, and comment out the line that
uses the macro, my code compiles cleanly. That is to say, "expanding
the macro" MANUALLY, i.e. "by hand," leads to successful compilation,
but letting the preprocessor do it leads to failiure-to-compile.
Can someone suggest a way around this? I also have g++ 3.4.3
available, although that's not what we use for standard development.
Thanks,
Chris
PS - the e-mail address appearing on this message is no longer valid,
so don't e-mail. My new address is similar but different:
(e-mail address removed) . I'll create a new Google Groups login soon...
Using g++ 3.3.1 on Linux ("Linux From Scratch") I have a data
structure SCSIParams_t that I wish to print out, field-by-field.
Rather than code a long line of the form
std::cout << "fieldname = " << basepointer->fieldname <<
std::endl;
for every field, I'd like to do it with a short macro, e.g.
EMITSCSI(SCSIDriverType);
I've coded a macro definition
#define EMITSCSI(fieldname) \
std::cout << # field << " = " << basepointer->##fieldname <<
std::endl
and coded, as a test, a single line identical to the "short macro,
e.g..." example shown above.
That line generates the compile error,
pasting "->" and "fieldname" does not give a valid
preprocessing token
However, using the -E switch on the compile line, I find that the
macro does, in fact, expand to a line identical to the "long line..."
shown above. In fact, if I cut-and-paste the expansion text from the
preprocessor output into my source file, and comment out the line that
uses the macro, my code compiles cleanly. That is to say, "expanding
the macro" MANUALLY, i.e. "by hand," leads to successful compilation,
but letting the preprocessor do it leads to failiure-to-compile.
Can someone suggest a way around this? I also have g++ 3.4.3
available, although that's not what we use for standard development.
Thanks,
Chris
PS - the e-mail address appearing on this message is no longer valid,
so don't e-mail. My new address is similar but different:
(e-mail address removed) . I'll create a new Google Groups login soon...