public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* cpp and ##: spurious blank causes "error: exponent has no digits"
@ 2012-09-14  7:11 Georg-Johann Lay
  2012-09-14  7:42 ` Bert Wesarg
  0 siblings, 1 reply; 2+ messages in thread
From: Georg-Johann Lay @ 2012-09-14  7:11 UTC (permalink / raw)
  To: gcc-help

Hi, consider the following C code that tries to compose literals that 
use gcc's P extension:

#define VAL1(X, SUFFIX) \
     X##SUFFIX

int x1 = VAL1 (0x123, P-2u);

#define VAL2(X, SUFFIX) \
     X##P-2##SUFFIX

int x2 = VAL2 (0x123, u);

Compiling this runs into "error: exponent has no digits" error because
cpp introduces a bad blank before the minus (same with +).

cpp expands the code to (with -P -g3):

#define VAL1(X,SUFFIX) X ##SUFFIX
int x1 = 0x123P -2u;
#define VAL2(X,SUFFIX) X ##P-2 ##SUFFIX
int x2 = 0x123P -2u;

Is this a bug or a feature?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: cpp and ##: spurious blank causes "error: exponent has no digits"
  2012-09-14  7:11 cpp and ##: spurious blank causes "error: exponent has no digits" Georg-Johann Lay
@ 2012-09-14  7:42 ` Bert Wesarg
  0 siblings, 0 replies; 2+ messages in thread
From: Bert Wesarg @ 2012-09-14  7:42 UTC (permalink / raw)
  To: Georg-Johann Lay; +Cc: gcc-help

On Fri, Sep 14, 2012 at 9:10 AM, Georg-Johann Lay <avr@gjlay.de> wrote:
> Hi, consider the following C code that tries to compose literals that use
> gcc's P extension:
>
> #define VAL1(X, SUFFIX) \
>     X##SUFFIX
>
> int x1 = VAL1 (0x123, P-2u);
>
> #define VAL2(X, SUFFIX) \
>     X##P-2##SUFFIX
>
> int x2 = VAL2 (0x123, u);
>
> Compiling this runs into "error: exponent has no digits" error because
> cpp introduces a bad blank before the minus (same with +).
>
> cpp expands the code to (with -P -g3):
>
> #define VAL1(X,SUFFIX) X ##SUFFIX
> int x1 = 0x123P -2u;
> #define VAL2(X,SUFFIX) X ##P-2 ##SUFFIX
> int x2 = 0x123P -2u;
>
> Is this a bug or a feature?

Feature, try this:

#define VAL2_(X, SUFFIX) \
    X##-##SUFFIX
#define VAL2(X, SUFFIX) \
    VAL2_(X##P, 2##SUFFIX)

Bert

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-09-14  7:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-14  7:11 cpp and ##: spurious blank causes "error: exponent has no digits" Georg-Johann Lay
2012-09-14  7:42 ` Bert Wesarg

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).