Preprocessor question...

Glen Nakamura gen@lava.net
Thu Feb 15 15:38:00 GMT 2001


Is the following valid code?

#include <stdio.h>
#define OFFSET (0x1000)
#define NUMBER (0x0E+OFFSET)
int main()
{
    printf("%d\n", NUMBER);
    return 0;
}

I get the following error when compiling with egcs-1.1.2 or gcc-2.95.2:

test.c: In function `main':
test.c:8: missing white space after number `0x0E'
test.c:8: `OFFSET' undeclared (first use in this function)
test.c:8: (Each undeclared identifier is reported only once
test.c:8: for each function it appears in.)

The code works if I put spaces around the "+":
e.g. #define NUMBER (0x0E + OFFSET)

My guess is the preprocessor thinks "0x0E+" is a floating point constant?
Anyway, the code also works if I use a different hex digit:
e.g. #define NUMBER (0x0A+OFFSET)

Not really a big deal, I'm just curious...
Anyone have an explanation?

Thanks,
 - Glen Nakamura



More information about the Gcc-bugs mailing list