* Record aggregate question (language lawyer needed!)
@ 1996-06-21 0:00 mcriley on BIX
1996-06-21 0:00 ` Theodore E. Dennison
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: mcriley on BIX @ 1996-06-21 0:00 UTC (permalink / raw)
The following test program is accepted without question by one Ada
compiler and executes without any qualms, while another warns of
a constraint_error at runtime. Which is correct, or, is the exact
implementation left up to the compiler implementor?
procedure Rec_Test is
type Task_Record_Type is
record
Originator : String (1 .. 20);
Header_Dtg : String (1 .. 12);
end record;
Task_Record : Task_Record_Type := (others => (others => ' '));
begin
null;
end rec_test;
The relevant part of the LRM is 4.3.1[1]: "A component association
with the choice others [...] is only allowed if the represented
components are all of the same type." Well the components are
both of the same _type_, but obviously the subtype constraints vary.
The nature of the warning produced by the one compiler reflects
that: "Subtype_Match_Error".
Any input on this would be most appreciated.
Marc A. Criley
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Record aggregate question (language lawyer needed!)
1996-06-21 0:00 Record aggregate question (language lawyer needed!) mcriley on BIX
@ 1996-06-21 0:00 ` Theodore E. Dennison
1996-06-22 0:00 ` Robert A Duff
` (2 more replies)
1996-06-21 0:00 ` Robert A Duff
1996-06-21 0:00 ` Norman H. Cohen
2 siblings, 3 replies; 8+ messages in thread
From: Theodore E. Dennison @ 1996-06-21 0:00 UTC (permalink / raw)
mcriley on BIX wrote:
> type Task_Record_Type is
> record
> Originator : String (1 .. 20);
> Header_Dtg : String (1 .. 12);
> end record;
>
> Task_Record : Task_Record_Type := (others => (others => ' '));
>
> The relevant part of the LRM is 4.3.1[1]: "A component association
> with the choice others [...] is only allowed if the represented
> components are all of the same type." Well the components are
Technically, I think they are of two different (anonymous) types,
both of which happen to be subtypes of STRING.
--
T.E.D.
| Work - mailto:dennison@escmail.orl.mmc.com |
| Home - mailto:dennison@iag.net |
| URL - http://www.iag.net/~dennison |
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Record aggregate question (language lawyer needed!)
1996-06-21 0:00 ` Theodore E. Dennison
@ 1996-06-22 0:00 ` Robert A Duff
1996-06-24 0:00 ` Philip Brashear
1996-06-24 0:00 ` Norman H. Cohen
2 siblings, 0 replies; 8+ messages in thread
From: Robert A Duff @ 1996-06-22 0:00 UTC (permalink / raw)
In article <31CAEC7B.446B9B3D@escmail.orl.mmc.com>,
Theodore E. Dennison <dennison@escmail.orl.mmc.com> wrote:
>mcriley on BIX wrote:
>> The relevant part of the LRM is 4.3.1[1]: "A component association
>> with the choice others [...] is only allowed if the represented
>> components are all of the same type." Well the components are
>
>Technically, I think they are of two different (anonymous) types,
>both of which happen to be subtypes of STRING.
No. Mcriley is correct -- they are of the same type (type String), but
different subtypes.
- Bob
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Record aggregate question (language lawyer needed!)
1996-06-21 0:00 ` Theodore E. Dennison
1996-06-22 0:00 ` Robert A Duff
@ 1996-06-24 0:00 ` Philip Brashear
1996-06-25 0:00 ` Theodore E. Dennison
1996-06-24 0:00 ` Norman H. Cohen
2 siblings, 1 reply; 8+ messages in thread
From: Philip Brashear @ 1996-06-24 0:00 UTC (permalink / raw)
In article <31CAEC7B.446B9B3D@escmail.orl.mmc.com>,
Theodore E. Dennison <dennison@escmail.orl.mmc.com> wrote:
>Technically, I think they are of two different (anonymous) types,
>both of which happen to be subtypes of STRING.
>
>
>--
>T.E.D.
> | Work - mailto:dennison@escmail.orl.mmc.com |
> | Home - mailto:dennison@iag.net |
> | URL - http://www.iag.net/~dennison |
'Fraid not, T.E.D. As you (almost) stated yourself, they're both of type
STRING. It's type that counts here, not subtype. Note the component
declarations themselves: they include a type name (STRING), plus a constraint.
They're not anonymous.
(This whole question of "others" in aggregates has always been a tough one
to explain.)
Phil Brashear
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Record aggregate question (language lawyer needed!)
1996-06-24 0:00 ` Philip Brashear
@ 1996-06-25 0:00 ` Theodore E. Dennison
0 siblings, 0 replies; 8+ messages in thread
From: Theodore E. Dennison @ 1996-06-25 0:00 UTC (permalink / raw)
Philip Brashear wrote:
>
> In article <31CAEC7B.446B9B3D@escmail.orl.mmc.com>,
> Theodore E. Dennison <dennison@escmail.orl.mmc.com> wrote:
> >Technically, I think they are of two different (anonymous) types,
> >both of which happen to be subtypes of STRING.
> >
> 'Fraid not, T.E.D. As you (almost) stated yourself, they're both of type
> STRING. It's type that counts here, not subtype. Note the component
> declarations themselves: they include a type name (STRING), plus a constraint.
> They're not anonymous.
>
> (This whole question of "others" in aggregates has always been a tough one
> to explain.)
...Tough to figure out too.
:-)
--
T.E.D.
| Work - mailto:dennison@escmail.orl.mmc.com |
| Home - mailto:dennison@iag.net |
| URL - http://www.iag.net/~dennison |
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Record aggregate question (language lawyer needed!)
1996-06-21 0:00 ` Theodore E. Dennison
1996-06-22 0:00 ` Robert A Duff
1996-06-24 0:00 ` Philip Brashear
@ 1996-06-24 0:00 ` Norman H. Cohen
2 siblings, 0 replies; 8+ messages in thread
From: Norman H. Cohen @ 1996-06-24 0:00 UTC (permalink / raw)
In article <31CAEC7B.446B9B3D@escmail.orl.mmc.com>, "Theodore E. Dennison"
<dennison@escmail.orl.mmc.com> writes:
|> Technically, I think they are of two different (anonymous) types,
|> both of which happen to be subtypes of STRING.
Newcomers trying to learn Ada are urged to ignore this misstatement,
which can only serve to confuse. It reflects a fundamental
misunderstanding of the relationships among types and subtypes.
All subtypes of String are of the same type, namely type String!
--
Norman H. Cohen ncohen@watson.ibm.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Record aggregate question (language lawyer needed!)
1996-06-21 0:00 Record aggregate question (language lawyer needed!) mcriley on BIX
1996-06-21 0:00 ` Theodore E. Dennison
@ 1996-06-21 0:00 ` Robert A Duff
1996-06-21 0:00 ` Norman H. Cohen
2 siblings, 0 replies; 8+ messages in thread
From: Robert A Duff @ 1996-06-21 0:00 UTC (permalink / raw)
In article <mcriley.835361851@BIX.com>, mcriley on BIX <mcriley@BIX.com> wrote:
> type Task_Record_Type is
> record
> Originator : String (1 .. 20);
> Header_Dtg : String (1 .. 12);
> end record;
>
> Task_Record : Task_Record_Type := (others => (others => ' '));
This is fine -- no exception should be raised. The inner aggregate
needds to get evaluated twice, and will have different bounds those two
times.
IMHO, "others" should not have been allowed in record aggregates -- only
in array aggregates. It's just too weird, and it causes an unreasonable
amount of implementation difficulty.
- Bob
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Record aggregate question (language lawyer needed!)
1996-06-21 0:00 Record aggregate question (language lawyer needed!) mcriley on BIX
1996-06-21 0:00 ` Theodore E. Dennison
1996-06-21 0:00 ` Robert A Duff
@ 1996-06-21 0:00 ` Norman H. Cohen
2 siblings, 0 replies; 8+ messages in thread
From: Norman H. Cohen @ 1996-06-21 0:00 UTC (permalink / raw)
In article <mcriley.835361851@BIX.com>, mcriley@BIX.com (mcriley on BIX) writes:
|>
|> The following test program is accepted without question by one Ada
|> compiler and executes without any qualms, while another warns of
|> a constraint_error at runtime. Which is correct, or, is the exact
|> implementation left up to the compiler implementor?
|>
|> procedure Rec_Test is
|>
|> type Task_Record_Type is
|> record
|> Originator : String (1 .. 20);
|> Header_Dtg : String (1 .. 12);
|> end record;
|>
|> Task_Record : Task_Record_Type := (others => (others => ' '));
|>
|> begin
|> null;
|> end rec_test;
|>
|> The relevant part of the LRM is 4.3.1[1]: "A component association
|> with the choice others [...] is only allowed if the represented
|> components are all of the same type." Well the components are
|> both of the same _type_, but obviously the subtype constraints vary.
Since you quote the Ada-83 RM, Ada-83 AI-00244 applies. The summary of
that AI is:
In a record aggregate, a component association having multiple choices
denoting components of the same type is considered equivalent to a
sequence of single choice component associations representing the same
components.
Thus, what you have written is equivalent to
Task_Record: Task_Record_Type :=
(Originator => (others => ' '),
Header_Dtg => (others => ' ') );
It should work without problem. Perhaps the compiler that raises
Constraint_Error (or threatens to) predates AI-00244, which received
final approval in November 1986.
The URL for the full text of AI83-00244 is:
ftp://sw-eng.falls-church.va.us/public/AdaIC/standards/83com/ai-00244-bi.wj
(By the way, the Ada-95 equivalent of the rule in RM83-4.3.1(1) is in the
last sentence of RM95-4.3.1(16). The effect of AI83-00244 is captured in
RM95-4.3.1(20).)
--
Norman H. Cohen ncohen@watson.ibm.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1996-06-25 0:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-06-21 0:00 Record aggregate question (language lawyer needed!) mcriley on BIX
1996-06-21 0:00 ` Theodore E. Dennison
1996-06-22 0:00 ` Robert A Duff
1996-06-24 0:00 ` Philip Brashear
1996-06-25 0:00 ` Theodore E. Dennison
1996-06-24 0:00 ` Norman H. Cohen
1996-06-21 0:00 ` Robert A Duff
1996-06-21 0:00 ` Norman H. Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox