I have a compiler error with GCC when trying to processor some macros from some TI code that compiles ok with the TI compiler.
The Macro's in question are some variation of
#define CHIP_FSET(Reg,Field,Val) _CHIP_##Reg##_FSET(##Field,Val)
and it is used in code like
CHIP_FSET(ST1_55, XF, CHIP_ST1_55_XF_OFF)
and when GCC gets a hold of that it says
error: pasting "(" and "XF" does not give a valid pre-processing token
It pre-processes successfully if I remove the ## in front of Field. If I am understanding the code correctly the ## in front of field seems irrelevant because it is turned into a function call (or another macro call) that takes two parameters. So the ## is redundant, the original replacement will result in ..._FSET(Field,Val) anyway.
So what am I missing? Everything I could find on the ## pre-processor directive said it just stuck the text together. So the ## never did anything in the first place in this case.
What am I missing?
And why would GCC choke on it but the TI compiler allow it? I'm guessing the answer to that is something like "ambiguous part of the spec".
=========================
Update
I think the problem is because there is a host of nested macros that might not be being completely resolved. What the compiler ends up with is invalid so it spits the dummy at some point in processing them all.
I've managed to make the problem worse by filling in the missing macros and it has caused some others parts to break. Such are the joys of porting code between platforms and compilers I guess.
Thanks for the help.
No the specs are not ambiguous. ##
operates on the level of tokens. It is required that the two tokens that are pasted together must form a valid token, again. (
doesn't form a token with alpha characters, thus the error message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With