preprocessor/5234: Variable arguments list in macro fail with another macro inclusion

Zack Weinberg zack@codesourcery.com
Tue Jan 1 11:16:00 GMT 2002


The following reply was made to PR preprocessor/5234; it has been noted by GNATS.

From: Zack Weinberg <zack@codesourcery.com>
To: david.taillandier@domainename.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: preprocessor/5234: Variable arguments list in macro fail with another macro inclusion
Date: Tue, 1 Jan 2002 11:08:25 -0800

 On Tue, Jan 01, 2002 at 06:36:32PM -0000, david.taillandier@domainename.com wrote:
 
 
 > #define    PROBLEM_HERE( text, vargs... ) \
         printf( text _("ending string\n"),  ## vargs )
 > #define NO_PROBLEM_HERE( text, vargs... ) \
         printf( text _("ending string\n") , ## vargs )
 
 You've run afoul of a clearly documented misfeature of gcc 2.x.
 
 	`##' before a rest argument that is empty discards the
 	preceding sequence of non-whitespace characters from the macro
 	definition. (If another macro argument precedes, none of it is
 	discarded.)
 
 What that means is,
 
 	PROBLEM_HERE ( "123" )
 
 expands to
 
 	printf ( "123" _ ( "ending )
 
 which is obviously not what you want.  The space before the comma is
 mandatory if you want your code to work with gcc 2.x.
 
 In gcc 3.0 we changed this extension so that only the comma gets
 deleted.  Your example code works correctly with that version of the
 compiler.
 
 zw



More information about the Gcc-prs mailing list