[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Scoping fix
From: |
Elijah Stone |
Subject: |
Re: [Tinycc-devel] Scoping fix |
Date: |
Thu, 21 Jan 2021 20:39:23 -0800 (PST) |
On Thu, 21 Jan 2021, Elijah Stone wrote:
On Thu, 21 Jan 2021, Michael Matz wrote:
You can't declare a struct in the declaration part of the for stmt
(6.8.5p3), only objects of auto and register class.
Hmmm. I think the spec is somewhat ambiguous here.
*snip*
FWIW Clang and 'The New C Standard: An Economic and Cultural Commentary'
(https://people.ece.cornell.edu/land/courses/ece4760/cbook1_1.pdf) agree
with GCC. But ICC, MSVC, and CompCert take the opposite view.
Another expression of the inconsistency, which I think makes it even
clearer: under this interpretation, the first two of the following forms
are allowed but the third is not:
// 1, ok
int i; for (i = sizeof(struct foo { int m; });;)
// 2, ok
int i = sizeof(struct foo { int m; });
// 3, not ok; why not?
for (int i = sizeof(struct foo { int m; });;)
I suspect that no one ever intended for it to be possible to declare an
identifier inside of an expression, and now we're dealing with the
fallout. I don't know if there's a _good_ solution, but I think that the
most consistent option is to allow struct declarations there.
I've written a short paper on the topic outlining the problem and a few
potential solutions for future versions of the spec; would appreciate any
feedback: https://elronnd.net/sl.pdf
-E