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

On Fri, Aug 11, 2000 at 11:58:11PM -0400, Byron Stanoszek wrote:
> 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?

Very recent versions of gcc should not give that warning for the
specific case of , ## <rest argument>.

You could also write your tprintf() macro like this:

#define tprintf(args...) (snprintf(buff, BUFSIZ, args), (char *)buff)

you'll still get an error for tprintf(/* nothing */) but
tprintf("string") will be fine.

zw

  reply	other threads:[~2000-08-11 23:31 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
2000-08-11 23:31     ` Zack Weinberg [this message]
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=20000811233046.A18374@wolery.cumb.org \
    --to=zack@wolery.cumb.org \
    --cc=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).