Hello!
That's probably an old problem, but I haven't found any notion of
it in GCC docs. So...
I need to have a macro which takes ONE argument, and either
ignores it or outputs a "=arg":
#ifdef __SOMEFILE_C
#define D
#define V(value) = value
#else
#define D extern
#define V(value)
#endif /* __SOMEFILE_C */
(The file itself is somefile.h, and it must either define variables if
included from somefile.c, or simply declare the same variables, when
included from other source files.)
This works fine, until I try to pass it some complex value:
D int some_array[2] V({4,5})
causes an error stating that I'm trying to pass two parameters when only
one is expected.
This looks like C preprocessor is slightly inadequate... What I'm
passing is a SIGNLE valid C expression, but, due to intentionally-ignorant
nature of CPP, curly braces aren't recognized and the expression is
treated as TWO separate arguments...
I've tried the "usual" trick -- adding extra braces:
D int some_array[2] V(({4,5}))
but that doesn't work either --
error: braced-group within expression allowed only inside a function
(this error is issued by both gcc-2.95 and gcc-3.4.4; haven't checked
gcc-4 yet).
Sure, I can "#define COMMA ," and write "V({4 COMMA 5})", but
that's ugly and leads to other undesired consequences.
The question is: the construct I'm trying to use is quite
reasonable -- is there any "good" solution for this problem?
Thanks in advance!
_________________________________________
Dmitry Yu. Bolkhovityanov
The Budker Institute of Nuclear Physics
Novosibirsk, Russia