a preprocessor bug (?) on processing a floating constant

Jonathan Wakely jwakely.gcc@gmail.com
Sat Nov 22 18:29:01 GMT 2025


On Sat, 22 Nov 2025, 14:43 Andrew Makhorin via Gcc-help, <
gcc-help@gcc.gnu.org> wrote:

> [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?
>

I think GCC is correct. E+2 is not a single preprocessor token, so the ##
operator pastes 1.23 and E but the +2 stays separate.


More information about the Gcc-help mailing list