comp.lang.ada
 help / color / mirror / Atom feed
* Suggestion for Ada 0X - "Complete" Record Rep Clauses
@ 2001-09-09  1:08 Chris Miller
  2001-09-09 12:42 ` Marc A. Criley
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Chris Miller @ 2001-09-09  1:08 UTC (permalink / raw)


Here is a quick suggestion for Ada 0X. I have no idea if it has been
suggested before.

Record representation clauses (LRM13.5.1) allow the locations for the
components of a record to be specified, but there is no way to ensure that
the location for each and every field is specified. If you do not specify
the location for a component then the compiler can put it anywhere. This is
generally not what is wanted, if a rep clause is used then typically the
location of all fields will need to be specified.

Assume you have

type R is record
  field1 : typea;
  field2 : typeb;
  field3 : typec;
end record;

for R use record
  field1 at 0 range ...;
  field3 at 3 range ...;
end record;

This is probably an error, since the location for field2 has been left out.
In this example it is blatantly obvious, however in real world code (for
example the layout of bus messages) there can be many fields and it is easy
to leave one out. This can lead to hard to find errors.

The addition could be to allow an optional reserved work "all" in the record
rep clause, in this case it would be a compile time error if the component
clauses for all fields were not specified.

So you would get

for R use all record
  field1 at 0 range ...;
  field2 at 3 range ...;
  field3 at 7 range ...;
end record;

This would be trivial to implement, and 100% upward compatible with current
code. May also wish to have a pragma that specifies that all record rep
clauses in its scope are complete. This could be either a new pragma or part
of pragma Restrictions, in the Safety & Security Annex.

Comments ??

Chris Miller
chrismil at ozemail dot com dot au
9 Sept 2001.






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Suggestion for Ada 0X - "Complete" Record Rep Clauses
  2001-09-09  1:08 Suggestion for Ada 0X - "Complete" Record Rep Clauses Chris Miller
@ 2001-09-09 12:42 ` Marc A. Criley
  2001-09-09 15:53 ` Robert Dewar
  2001-09-10  5:44 ` Florian Weimer
  2 siblings, 0 replies; 6+ messages in thread
From: Marc A. Criley @ 2001-09-09 12:42 UTC (permalink / raw)


Chris Miller wrote:
> 
> Here is a quick suggestion for Ada 0X. I have no idea if it has been
> suggested before.
> 
   <snip>
> 
> The addition could be to allow an optional reserved work "all" in the record
> rep clause, in this case it would be a compile time error if the component
> clauses for all fields were not specified.
> 
> So you would get
> 
> for R use all record
>   field1 at 0 range ...;
>   field2 at 3 range ...;
>   field3 at 7 range ...;
> end record;
> 
> This would be trivial to implement, and 100% upward compatible with current
> code. May also wish to have a pragma that specifies that all record rep
> clauses in its scope are complete. This could be either a new pragma or part
> of pragma Restrictions, in the Safety & Security Annex.

Chris, I think this is a good idea.  Aside from its utility, you note
that it is upward comptatible and would [should] be easy to
implement--two aspects that make it easier to get changes through the
language revision process.  The other test that needs to be passed is
"Has this caused a problem for someone in the past?"  And I can attest
that I have run into bugs in the past that this modification would've
helped avoid.

I would suggest that you submit this for consideration in accordance
with the "Instructions for Comment Submission" as provided in the Ada
Reference Manual: http://www.ada-auth.org/arm-html/RM-0-3.html.  One
thing you might want to do first is surf around the Ada Conformity
Assessment Authority website (www.ada-auth.org) so you can see how such
suggestions are put together.

Once you've sent this to the e-mail list (which is what following the
"Instructions" does), I will add some discussion there about my
experiences pertaining to the problem your suggestion is addressing.

Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Suggestion for Ada 0X - "Complete" Record Rep Clauses
  2001-09-09  1:08 Suggestion for Ada 0X - "Complete" Record Rep Clauses Chris Miller
  2001-09-09 12:42 ` Marc A. Criley
@ 2001-09-09 15:53 ` Robert Dewar
  2001-09-10  5:44 ` Florian Weimer
  2 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 2001-09-09 15:53 UTC (permalink / raw)


"Chris Miller" <chrismil@ozemail.com.au> wrote in message news:<tmCm7.2113$iH4.154993@ozemail.com.au>...
> Here is a quick suggestion for Ada 0X. I have no idea if it has been
> suggested before.


Probably you should submit suggestions following the
standard procedure as comments on the standard, 

A quick comment is that it is always good to check that the
compiler has layed out data structures as you expect if
it is critical. The -gnatR switch in GNAT is useful for
this purpose.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Suggestion for Ada 0X - "Complete" Record Rep Clauses
  2001-09-09  1:08 Suggestion for Ada 0X - "Complete" Record Rep Clauses Chris Miller
  2001-09-09 12:42 ` Marc A. Criley
  2001-09-09 15:53 ` Robert Dewar
@ 2001-09-10  5:44 ` Florian Weimer
  2001-09-10 12:13   ` Marc A. Criley
  2001-09-18 15:06   ` Lutz Donnerhacke
  2 siblings, 2 replies; 6+ messages in thread
From: Florian Weimer @ 2001-09-10  5:44 UTC (permalink / raw)


"Chris Miller" <chrismil@ozemail.com.au> writes:

> Record representation clauses (LRM13.5.1) allow the locations for the
> components of a record to be specified, but there is no way to ensure that
> the location for each and every field is specified. If you do not specify
> the location for a component then the compiler can put it anywhere. This is
> generally not what is wanted, if a rep clause is used then typically the
> location of all fields will need to be specified.

Specifying the representation only partially could be used in some
contexts, for example to rearrange some components so that they appear
in a single cache line.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Suggestion for Ada 0X - "Complete" Record Rep Clauses
  2001-09-10  5:44 ` Florian Weimer
@ 2001-09-10 12:13   ` Marc A. Criley
  2001-09-18 15:06   ` Lutz Donnerhacke
  1 sibling, 0 replies; 6+ messages in thread
From: Marc A. Criley @ 2001-09-10 12:13 UTC (permalink / raw)


Florian Weimer wrote:
> 
> "Chris Miller" <chrismil@ozemail.com.au> writes:
> 
> > Record representation clauses (LRM13.5.1) allow the locations for the
> > components of a record to be specified, but there is no way to ensure that
> > the location for each and every field is specified. If you do not specify
> > the location for a component then the compiler can put it anywhere. This is
> > generally not what is wanted, if a rep clause is used then typically the
> > location of all fields will need to be specified.
> 
> Specifying the representation only partially could be used in some
> contexts, for example to rearrange some components so that they appear
> in a single cache line.

We found that records having "partial rep specs" could have the
non-specified components layed out using quite different approaches by
different compilers (porting from Alsys Ada 83 to GNAT Ada 95).  There's
nothing wrong with that, it simply reinforces the notion that one has to
know what they're doing and be aware of potential pitfalls when porting.

Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Suggestion for Ada 0X - "Complete" Record Rep Clauses
  2001-09-10  5:44 ` Florian Weimer
  2001-09-10 12:13   ` Marc A. Criley
@ 2001-09-18 15:06   ` Lutz Donnerhacke
  1 sibling, 0 replies; 6+ messages in thread
From: Lutz Donnerhacke @ 2001-09-18 15:06 UTC (permalink / raw)


* Florian Weimer wrote:
>"Chris Miller" <chrismil@ozemail.com.au> writes:
>> Record representation clauses (LRM13.5.1) allow the locations for the
>
>Specifying the representation only partially could be used in some
>contexts, for example to rearrange some components so that they appear
>in a single cache line.

Other use:

   subtype length is Integer range 0 .. 255;
   type pstring (len : length) is record
      value : string (1 .. len);
   end record;
   
   for pstring use record
      len at 0 range 0 .. 7;
   end record;


-- 
   Mailbox der letzten vier Wochen kommentarlos in den Orkus getreten.
   Wichtige Anfragen bitte nochmal senden. Unter Angabe von Msg-ID oder
   markanten Suchworten, kann ich die Mails jedoch heraussuchen.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-09-18 15:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-09  1:08 Suggestion for Ada 0X - "Complete" Record Rep Clauses Chris Miller
2001-09-09 12:42 ` Marc A. Criley
2001-09-09 15:53 ` Robert Dewar
2001-09-10  5:44 ` Florian Weimer
2001-09-10 12:13   ` Marc A. Criley
2001-09-18 15:06   ` Lutz Donnerhacke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox