7

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.

4

1 回答 1

4

不,规格不是模棱两可的。##在代币级别上运行。要求粘贴在一起的两个令牌必须再次形成有效令牌。(不会形成带有字母字符的标记,因此会出现错误消息。

于 2013-10-30T23:09:16.360 回答