This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
`Cpp: 'ICOM_FN(##xfn)' generates a warning :-(
- To: gcc at gcc dot gnu dot org
- Subject: `Cpp: 'ICOM_FN(##xfn)' generates a warning :-(
- From: Francois Gouget <fgouget at free dot fr>
- Date: Tue, 2 Jan 2001 16:03:06 -0800 (PST)
- cc: jakub at redhat dot com
Hi,
I'm having problems with the following piece of code (extracted from
Wine's source):
#define GetObject You_cannot_use_GetObject_in_this_context
#define ICOM_FN(xfn) fn ## xfn
#define DECLARE1(xfn) void ICOM_FN(xfn) (void);
#define DECLARE2(xfn) void ICOM_FN(##xfn) (void);
ICOM_FN(GetObject)
DECLARE1(GetObject)
DECLARE2(GetObject)
I expect to get (blank and not relevant lines removed):
fnGetObject
void fnYou_cannot_use_GetObject_in_this_context (void);
void fnGetObject (void);
But I've had problems with recent versions of gcc. One version
(20001002) produced:
test.c:6:38: warning: nothing can be pasted after this token
fnGetObject
void fnYou_cannot_use_GetObject_in_this_context (void);
void fnYou_cannot_use_GetObject_in_this_context (void);
But more recent versions work again so this seems to be fixed. But I
still get the following warning:
test.c:11:1: warning: pasting "(" and "GetObject" does not give a valid
preprocessing token
Is this use of '##' still going to be supported in the future?
Is it possible to not issue a warning in this situation (I know about
the macro vararg problem).
Reading the Cpp documentation I see:
-- http://gcc.gnu.org/onlinedocs/cpp_1.html#SEC46
Attempting to paste two tokens which together do not form a valid
preprocessing token The preprocessor currently warns about this and
outputs the two tokens adjacently, which is probably the behavior the
programmer intends. It may not work in future, though. Most of the time,
when you get this warning, you will find that `##' is being used
superstitiously, to guard against whitespace appearing between two
tokens. It is almost always safe to delete the `##'.
--
But this does not cover what I do which is to use the concatenation
operator to avoid the argument prescan described in 'Separate Expansion
of Macro Arguments'
-- http://gcc.gnu.org/onlinedocs/cpp_toc.html#SEC29
We have explained that the expansion of a macro, including the
substituted arguments, is re-scanned for macro calls to be expanded.
What really happens is more subtle: first each argument is scanned
separately for macro calls. Then the resulting tokens are substituted
into the macro body to produce the macro expansion, and the macro
expansion is scanned again for macros to expand.
--
-- http://gcc.gnu.org/onlinedocs/cpp_toc.html#SEC29
The prescan is not done when an argument is stringified or concatenated.
--
Since this is unrelated to the macro vararg issue it would be nice if
there was a way to avoid the warning in this context (otherwise we'll
have to change the code and duplicate 30+ macros :-( ).
PS:
I apologize if this is the wrong mailing list. Would gcc-bugs be more
appropriate (seems like it is more gnats oriented)?
jakub, Bernhard Rosenkraenzer told me you would be interested in being
cc-ed.
--
Francois Gouget fgouget@free.fr http://fgouget.free.fr/
RFC 2549: ftp://ftp.isi.edu/in-notes/rfc2549.txt
IP over Avian Carriers with Quality of Service