a preprocessor bug (?) on processing a floating constant

Andrew Makhorin via Gcc-help <[email protected]>
Newsgroups gmane.comp.gcc.help
Message-ID <[email protected]>
[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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.