cpp and ##: spurious blank causes "error: exponent has no digits"

Georg-Johann Lay avr@gjlay.de
Fri Sep 14 07:11:00 GMT 2012


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?



More information about the Gcc-help mailing list