tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] arraystring, a simple C program which doesn't compile


From: Michael Matz
Subject: Re: [Tinycc-devel] arraystring, a simple C program which doesn't compile
Date: Sat, 20 Jun 2020 22:02:59 +0200 (CEST)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)

Hello,

On Wed, 3 Jun 2020, Michael Matz wrote:

 int main(void)
 {
     char a[2] = { abc[0], 0 };
     puts(a);
     return 0;
 }

 Output:
 arraystring.c:6: warning: initializer-string for array is too long
 arraystring.c:6: error: '}' expected (got "[")

 Interestingly this program works when a parenthesis is put around abc[0]:
 char a[2] = { (abc[0]), 0 };
 Alternatively, it also works if the parenthesis is around the defined
 string
 instead:
 #define abc ("abc")
 which can also be done at usage level:
 char a[2] = { (abc)[0], 0 };

 so maybe it's an issue with the parser?

Yes it is, specifically the parser for initializers. It tries to special-case string initialization to not use the general expression parser, and that bites us here. (The reason for that is to not commit the string to memory too early when it's used to initialize some static data) We really need to go through the normal expression parser for this case (which is why it works when adding parentheses around the string token), but that needs some work to not break other cases.

Fixed in mob now.


Ciao,
Michael.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]