This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: warning: pasting would not give a valid preprocessing token


On 11 Aug 2000, Geoff Keating wrote:

> Byron Stanoszek <gandalf@winds.org> writes:
> 
> > I've seen this warning in many of my .c files when compiling with versions of
> > 2.96 from mid-july and newer.. has anyone else seen this before, know what it
> > is, and how to fix it?
> > 
> > warning: pasting would not give a valid preprocessing token
> 
> It means you're writing something like
> 
> #define paste(a, b) a##b
> paste(*,foo)
> 
> because '*foo' is not a token, the tokens you want are '*' and 'foo'.
> The solution is to replace the ## with a space.

Strange, but true. I see the problem now. I have a #define like this:

/* tprintf(): prints to a temporary variable 16k in size */
extern char global_buff[16384];
#define tprintf(format, args...) (sprintf(global_buff, format, ## args), \
                                  (char *)global_buff)

But in my .c file, I use string concatenation like this:

  notify(player, tprintf("Your knowledge of %s is too low to speak "
         "it fluently.", language[ptr->num].name));

Can you tell me what the best way there is to get around that?

Also, this brings up another question with variable argument macros.

My intent is to use tprintf with 0 or more `args'. However, this is only
possible by using the ## operator in front of args. If that ## is removed,
then it only allows 1 or more arguments. Here is an example:

with ##:

tprintf("Foo\n");  =>  sprintf(global_buff, "Foo");

without ##:

tprintf("Foo\n");  =>  sprintf(global_buff, "Foo", );

(which results in a nice GCC error).


Any way to [correctly] achieve the zero-or-more arguments there without
munging 'format' (which is a mandatory part of that macro).

Thanks.

-- 
Byron Stanoszek                         Ph: (330) 644-3059
Systems Programmer                      Fax: (330) 644-8110
Commercial Timesharing Inc.             Email: bstanoszek@comtime.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]