Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Missing constraints?

5 views
Skip to first unread message

Miloslav Trmac

unread,
Jul 15, 2003, 1:21:16 PM7/15/03
to
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.

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

Andreas Schwab

unread,
Jul 15, 2003, 2:50:15 PM7/15/03
to
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.

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."

Jun Woong

unread,
Jul 16, 2003, 3:51:53 AM7/16/03
to

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

Clive D. W. Feather

unread,
Jul 16, 2003, 4:43:35 AM7/16/03
to
In article <bf1d6c$11ff$1...@cuce.ruk.cuni.cz>, 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.

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

unread,
Jul 16, 2003, 10:00:37 AM7/16/03
to
"Jun Woong" <myco...@hanmail.net> writes:

|> "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.

0 new messages