JoseD wrote:
> Hi. Just wanted to share that the following macro gives an error on latest
> versions of GCC, but is reported to work on 2.95.3 (tested on MorphOS but
> should be the same for other OSses of course).
> Both an old version of SASC(AmigaOS) and Borland (on X86) worked fine.
>
> #include<stdio.h>
>
> #define EXTRACTBRCKTELMNT(Terminator, Elmnt) #Elmnt, #Terminator
>
> #define GETBRCKTELMNT(ToExtract) \
(added backslash above)
> GETELMNTEXPAND(EXTRACTBRCKTELMNT##ToExtract)
> #define GETELMNTEXPAND(a) GETELMNTEXPAND2 (a)
> #define GETELMNTEXPAND2(a, b) a, b
>
>
> int main (int argc, char **argv)
> { printf("%s %s\n", GETBRCKTELMNT((YYY, XXX)));
>
> getchar();
> return (0);
> }
My preprocessor agree that this is incorrect code and not a
g++ bug:
Error: Invalid use of ## token pasting operator, result is not a single
preprocessing token: "EXTRACTBRCKTELMNT(" from "EXTRACTBRCKTELMNT" and
"(" gives 2 tokens; this is undefined by 16.3.3/3
-- James