M
Mark Odell
I'm running two different compilers against some hairy macros and one,
gcc, doesn't like my token pasting result so much. It says, " "." and
"foo" does not give a valid preprocessing token ". Some further reading
suggests that since .foo is not a valid preproc. token that I can't
really do what I want, portably. The macro looks like this:
#define DMA_CHECK_SR_BIT(reg, REG, ch) do \
{ \
DmaSr sr; \
\
sr.all = 0; \
sr.bit.##reg##ch = 1; \
\
printf("SR[" #REG "] = 0x%08X", sr.all); \
if (sr.all == DMA0_SR_##REG##_CHAN(ch)) \
{ \
printf(", okay\n"); \
} \
else \
{ \
printf(" != 0x%08X (FAIL)\n", DMA0_SR_##REG##_CHAN(ch)); \
} \
} while (0)
and DMA_CHECK_SR_BIT(cs, CS, 0) ends up creating what looks like
exactly what I want (sorry for the long line):
do { DmaSr sr; sr.all = 0; sr.bit.cs0 = 1; printf("SR[" "CS" "] =
0x%08X", sr.all); if (sr.all == DMA0_SR_CS_CHAN(0)) { printf(",
okay\n"); } else { printf(" != 0x%08X (FAIL)\n", DMA0_SR_CS_CHAN(0)); }
} while (0);
So I fear that gcc and the other compiler do the right thing, for me,
but I should re-write the macro to be more portable.
Comments? Thanks,
gcc, doesn't like my token pasting result so much. It says, " "." and
"foo" does not give a valid preprocessing token ". Some further reading
suggests that since .foo is not a valid preproc. token that I can't
really do what I want, portably. The macro looks like this:
#define DMA_CHECK_SR_BIT(reg, REG, ch) do \
{ \
DmaSr sr; \
\
sr.all = 0; \
sr.bit.##reg##ch = 1; \
\
printf("SR[" #REG "] = 0x%08X", sr.all); \
if (sr.all == DMA0_SR_##REG##_CHAN(ch)) \
{ \
printf(", okay\n"); \
} \
else \
{ \
printf(" != 0x%08X (FAIL)\n", DMA0_SR_##REG##_CHAN(ch)); \
} \
} while (0)
and DMA_CHECK_SR_BIT(cs, CS, 0) ends up creating what looks like
exactly what I want (sorry for the long line):
do { DmaSr sr; sr.all = 0; sr.bit.cs0 = 1; printf("SR[" "CS" "] =
0x%08X", sr.all); if (sr.all == DMA0_SR_CS_CHAN(0)) { printf(",
okay\n"); } else { printf(" != 0x%08X (FAIL)\n", DMA0_SR_CS_CHAN(0)); }
} while (0);
So I fear that gcc and the other compiler do the right thing, for me,
but I should re-write the macro to be more portable.
Comments? Thanks,