First, which constraint does the following translation unit violate?
typedef int i = 5;
AFAICS none of 6.7, 6.7.7 and 6.7.8 prohibits this explicitly.
Second, by current rules, the following two external declarations do not
violate any constraint:
int n, i;
int *p = (int *)(int (*)[n])&i;
(that is, address constant can contain casts to VM types). I can live
with that, I just wonder whether this is intentionally allowed.
(Yes, the cast may invoke UB, but I believe that's not relevant here).
Thanks,
Mirek
|> Hello,
|> Another two questions.
|>
|> First, which constraint does the following translation unit violate?
|> typedef int i = 5;
|> AFAICS none of 6.7, 6.7.7 and 6.7.8 prohibits this explicitly.
Do types have a type?
6.7.8#2: The type of the entity to be initialized shall be an array of
unknown size or an object type that is not a variable length array
type.
Andreas.
--
Andreas Schwab, SuSE Labs, sch...@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
You meant 6.7.8p3? C90 has a better one in 6.5.7 (constraints):
There shall be no more initializers in an initializer list than
there are objects to be initialized.
which is similar to the real 6.7.8p2:
No initializer shall attempt to provide a value for an object not
contained within the entity being initialized.
--
Jun, Woong (myco...@hanmail.net)
Dept. of Physics, Univ. of Seoul
6.7.8:
[#2] No initializer shall attempt to provide a value for an
object not contained within the entity being initialized.
Since "i" is not an object, any initializer will be attempting to
initialize an object not contained within it.
There was a loose proposal to allow this as an extension. Under it,
anything declared with "i" rather than "int" would be initialized to 5
if no initializer was given.
>Second, by current rules, the following two external declarations do not
>violate any constraint:
> int n, i;
> int *p = (int *)(int (*)[n])&i;
>(that is, address constant can contain casts to VM types). I can live
>with that, I just wonder whether this is intentionally allowed.
>(Yes, the cast may invoke UB, but I believe that's not relevant here).
As far as I can see, it's allowed. However, I'm not sure if it should
be: consider:
int *p = (int *)(int (*)[n][n])&i;
where the size of the second dimension affects something like alignment.
--
Clive D.W. Feather, writing for himself | Home: <cl...@davros.org>
Tel: +44 20 8371 1138 (work) | Web: <http://www.davros.org>
Fax: +44 870 051 9937 | Work: <cl...@demon.net>
Written on my laptop; please observe the Reply-To address
|> "Andreas Schwab" <sch...@suse.de> wrote in message news:je1xwrv...@sykes.suse.de...
|> > Miloslav Trmac <tr...@popelka.ms.mff.cuni.cz> writes:
|> >
|> > |> Hello,
|> > |> Another two questions.
|> > |>
|> > |> First, which constraint does the following translation unit violate?
|> > |> typedef int i = 5;
|> > |> AFAICS none of 6.7, 6.7.7 and 6.7.8 prohibits this explicitly.
|> >
|> > Do types have a type?
|> >
|> > 6.7.8#2: The type of the entity to be initialized shall be an array of
|> > unknown size or an object type that is not a variable length array
|> > type.
|> >
|>
|> You meant 6.7.8p3?
Yes, typo.