comp.lang.ada
 help / color / mirror / Atom feed
From: Anonymous Coward <bogus_addy@bogus_domain.net>
Subject: Re: Default rep specs for record types - documented??
Date: Sat, 05 Nov 2005 03:33:43 GMT
Date: 2005-11-05T03:33:43+00:00	[thread overview]
Message-ID: <slrndmoh1u.b6j.bogus_addy@tango.mindfuq.org> (raw)
In-Reply-To: uacgktuhd.fsf@acm.org

In article <uacgktuhd.fsf@acm.org>, Stephen Leake wrote:
>>
>> What's disappointing is that rep specs add considerable clutter.
> 
> Yes. Ada explicitly favors being precise over being concise.

Precision need not be at odds with conciseness.  Consider an
enumerated type:

  type my_enum is (first, second, third);

I am *guaranteed* by the LRM that the representation will code "first"
as zero, "second" as 1, and "third" as 2.  Adding this rep spec:

  for my_enum use (first => 0, second => 1, third => 2);

gives me no more precision, yet it dirties the code.  

Consequently, I will never rep spec an enum unless I intend to deviate
from the default rep spec.  And when I do deviate, the code will be
more readable, because the reader will say "hey wait a minute, why is
this rep spec'd and the others are not.. hmm.. there's something
different here.."  So differences will stand out, as they should.

So being able to count on default representations (which are
changable) is a good thing, because you can be both precise and
concise.

However, in the case of records, I've changed my opinion based on what
I've read here.  A compiler should be given opportunity to optimize
where practical, and imposing a default rep spec could hinder the
compilers ability to optimize record layout.

>> Readable code avoids redundancy, so having default representation
>> aspects that are guaranteed enable less noisey code. 
> 
> Representation clauses are not 'redundant'; they provide information
> that is not provided by the type declaration.

That seems to depend on what aspect of what kind of type we're talking
about.  In the enum case above, the "for .. use" rep spec *is*
redundant.  

> One problem is that the compiler does _not_ warn you if you leave a
> component out of the rep clause; a 'pragma Complete_Representation'
> would be nice. Specifying the total size can mitigate this, but I
> recently had a bug due to this problem.

I can think of cases where rep spec'ing partial records would be
useful.  But I would agree that there should certainly be a warning.

>> I'm not looking forward to rep specing records bit for bit simply to
>> enforce the same order of elements that's specified in the operation
>> specs.
> 
> If 'operation specs' are defining the hardware you are interfacing
> to, then yes, you need a rep clause for each hardware register. The
> time spent writing those clauses _will_ be repaid later when it
> comes to testing on the hardware; there _will_ be fewer bugs.

Perhaps, but for interfacing with C operations (which is my case), I
would prefer to simply write "pragma convention (C, my_record)" and be
able to expect the compiler to base the representational spec purely
off the operational spec, just as the C compiler would for a structure
that only has an operational spec.  

I should not have to micromanage the bitwise layout of a record to
interface with C code.  It puts me at a lower level, and positions me
to make human errors (like writing an incomplete rep spec for a
record), when such errors can be avoided by keeping it high level.

> Someone mentioned a 'pragma Preserve_Layout', which presumably means
> "assume a representation clause that puts things in declaration order,
> with the base size for each component, and no gaps". That would be
> useful, in situations where the type declarations do in fact match the
> hardware precisely. Hmm. That is true for most of the rep clauses I've
> written recently. I'll have to suggest that to AdaCore as a possible
> enhancement; it would have prevented my bug. 

Yes, I agree.. that would be useful.  Or maybe better yet, mandate
that pragma convention (C,...) matches representation order to
declaration order to keep the number of pragmas minimal.



  parent reply	other threads:[~2005-11-05  3:33 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-04  2:21 Default rep specs for record types - documented?? Anonymous Coward
2005-11-04  2:36 ` Steve
2005-11-04  4:11   ` Anonymous Coward
2005-11-04  5:30     ` Jeffrey R. Carter
2005-11-05  3:13       ` Steve
2005-11-05  4:45         ` Jeffrey R. Carter
2005-11-06 14:05           ` Steve
2005-11-06 16:08             ` Anonymous Coward
2005-11-07  7:25             ` Jeffrey R. Carter
2005-11-08 13:36               ` Steve
2005-11-14  1:12             ` Robert A Duff
2005-11-14  3:03               ` Anonymous Coward
2005-11-14 18:08                 ` Jeffrey R. Carter
2005-11-14 18:49                 ` Robert A Duff
2005-11-15  1:16                   ` ADA compilers can reject types arbitrarily? Anonymous Coward
2005-11-15  2:10                     ` tmoran
2005-11-15  3:12                     ` Robert A Duff
2005-11-15  6:44                     ` Simon Wright
2005-11-16  0:16                       ` Adaists Deny Acronym. (was: ADA compilers can reject types arbitrarily?) Björn Persson
2005-11-16  5:38                         ` Adaists Deny Acronym Simon Wright
2005-11-16  6:16                         ` Adaists Deny Acronym. (was: ADA compilers can reject types arbitrarily?) Samuel Tardieu
2005-11-15 12:43                     ` ADA compilers can reject types arbitrarily? Jeff Creem
2005-11-14 21:14                 ` Default rep specs for record types - documented?? Simon Wright
2005-11-04 13:26     ` Stephen Leake
2005-11-04 14:33       ` Marc A. Criley
2005-11-04 18:35         ` Georg Bauhaus
2005-11-04 20:07           ` Britt Snodgrass
2005-11-04 14:39       ` Stephen Leake
2005-11-04 15:27         ` Britt Snodgrass
2005-11-04 15:55           ` Lauri Ora
2005-11-04 21:42             ` Larry Kilgallen
2005-11-05  2:26             ` Anonymous Coward
2005-11-05  2:42               ` Frank J. Lhota
2005-11-05  3:27               ` Ed Falis
2005-11-05  3:55                 ` Anonymous Coward
2005-11-05  4:07                 ` Lauri Ora
2005-11-05 13:46                   ` Ed Falis
2005-11-05 10:14                 ` Stephen Leake
2005-11-04 16:52         ` Frank J. Lhota
2005-11-04 16:57           ` Frank J. Lhota
2005-11-04 23:27           ` tmoran
2005-11-05 10:25           ` Stephen Leake
2005-11-14  1:09             ` Robert A Duff
2005-11-05  3:33       ` Anonymous Coward [this message]
2005-11-05 10:34         ` Stephen Leake
2005-11-05 16:35           ` ADA/C interfaces: type representations uncontrollable in C Anonymous Coward
2005-11-05 16:49             ` Ed Falis
2005-11-05 18:24             ` tmoran
2005-11-09  2:12           ` 'Size can mean value size OR object size, depending Anonymous Coward
2005-11-09  3:27             ` Jeffrey R. Carter
2005-11-09  4:04               ` Anonymous Coward
2005-11-05 14:27         ` Default rep specs for record types - documented?? Michael Bode
2005-11-05 16:17           ` pragma convention Anonymous Coward
2005-11-06  1:07             ` Jeffrey R. Carter
2005-11-06 22:22               ` Anonymous Coward
2005-11-07  7:34                 ` Jeffrey R. Carter
2005-11-05 14:39         ` Default rep specs for record types - documented?? Martin Krischik
2005-11-04  9:40   ` Martin Dowie
2005-11-04 14:36   ` Marc A. Criley
2005-11-04 17:45 ` Martin Krischik
replies disabled

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