public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Byron Stanoszek <gandalf@winds.org>
To: Geoff Keating <geoffk@cygnus.com>
Cc: gcc@gcc.gnu.org
Subject: Re: warning: pasting would not give a valid preprocessing token
Date: Fri, 11 Aug 2000 20:58:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.21.0008112353260.6823-100000@winds.org> (raw)
In-Reply-To: <jmlmy3b0qg.fsf@envy.cygnus.com>

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

  reply	other threads:[~2000-08-11 20:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-08-11 20:41 Byron Stanoszek
2000-08-11 20:46 ` Geoff Keating
2000-08-11 20:58   ` Byron Stanoszek [this message]
2000-08-11 23:31     ` Zack Weinberg
2000-08-12  8:19       ` Byron Stanoszek
2000-09-06 19:18         ` Zack Weinberg
2000-09-07 12:04           ` Byron Stanoszek
2000-09-11 21:44             ` Zack Weinberg
     [not found] <20000914185040.A12722@daikokuya.demon.co.uk>
     [not found] ` <Pine.LNX.4.21.0009141510140.21092-201000@winds.org>
2000-09-14 15:53   ` Neil Booth
2000-09-14 16:02     ` Neil Booth
2000-09-14 16:08     ` Jeffrey A Law
2000-09-15 16:53     ` Byron Stanoszek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.21.0008112353260.6823-100000@winds.org \
    --to=gandalf@winds.org \
    --cc=gcc@gcc.gnu.org \
    --cc=geoffk@cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).