a preprocessor bug (?) on processing a floating constant
Andrew Makhorin
mao@gnu.org
Sat Nov 22 14:41:46 GMT 2025
[Sorry for duplicating my message.]
Hi,
On preprocessing the program
#define x 1.23 ## E+2
int main(void)
{
printf("x = %g\n", x);
return 0;
}
the preprocessor generates the following
$ gcc -E test.c
# 0 "test.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "test.c"
int main(void)
{
printf("x = %g\n", 1.23E +2);
return 0;
}
Since x results in two tokens "1.23E" and "+2" rather than in one token
"1.23E+2", the compiler raises an error:
test.c:1:14: error: exponent has no digits
1 | #define x 1.23 ## E+2
| ^~~~
test.c:5:29: note: in expansion of macro 'x'
5 | printf("x = %g\n", x);
| ^
On the other hand, the Standard says (3.1.8 Preprocessing Numbers):
Preprocessing number tokens lexically include all floating and
integer constant tokens.
Is it a preprocessor bug? Or I miss something?
Thank you,
Andrew Makhorin
More information about the Gcc-help
mailing list