comp.lang.ada
 help / color / mirror / Atom feed
From: okellogg <okellogg@users.sourceforge.net>
Subject: Re: Should representation clauses be complete for each bit?
Date: Wed, 20 Jul 2011 12:14:48 -0700 (PDT)
Date: 2011-07-20T12:14:48-07:00	[thread overview]
Message-ID: <6666bbe0-8485-4b8d-b077-70ffea630151@l37g2000yqd.googlegroups.com> (raw)
In-Reply-To: wccwrfcvp41.fsf@shell01.TheWorld.com

On Jul 20, 7:27 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> [...]
> But that could happen with any component -- it doesn't have to be
> "spare" and set to zero.  What if the protocol requires "set this
> 3-bit gap to all 1's"?  Or what if there's a checksum component,
> which is set by the driver just before shipping the thing over
> the wire -- in that case, you wouldn't want to expose the checksum
> to clients.

Yes, I guess you're right.
The syntax you propose is much more general and flexible.

> Perhaps this is what you really want (note that this is illegal
> for all sorts of reasons):
>
>    type T1 is
>       record
>          One : Boolean;
>          Tooth : Boolean;
>          Ree : Boolean;
>       end record;
>
>    type T2 is new T1 with private; -- not Ada!
> private
>    type T2 is new T1 with
>       record
>          Gap1 : Bits2; -- must be zero
>          Gap2 : Bits11; -- must be zero
>       end record
>         with Predicate => T.Gap1 = 0 and T.Gap2 = 0;

I'd imagine that a default assignment at Gap1 and Gap2 would suffice?
         Gap1 : Bits2 := 0;

>    for T1 use
>       record
>          pragma Complete_Representation;
>          One at 0 range 0..0;
>          Tooth at 0 range 3..3;
>          Ree at 0 range 15..15;
>       end record;
>
>    for T2 use
>       record
>          pragma Complete_Representation;
>          Gap1 at 0 range 1..2;
>          Gap2 at 0 range 4..14;
>       end record;
>

I believe the compiler would warn about incomplete representation at
T1?

Also I guess an upcast from T2 to T1 should do for converting the
types but I'm not so sure about the downcast from T1 to T2?

-- Oliver



  reply	other threads:[~2011-07-20 19:14 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-20 10:34 Should representation clauses be complete for each bit? okellogg
2011-07-20 14:51 ` Robert A Duff
2011-07-20 15:24   ` Georg Bauhaus
2011-07-20 17:28     ` Robert A Duff
2011-07-21  7:37       ` Martin
2011-07-21  8:22         ` Simon Wright
2011-07-21 14:58           ` Robert A Duff
2011-07-23  0:13             ` Randy Brukardt
2011-07-27 14:12               ` okellogg
2011-07-28  0:03                 ` Randy Brukardt
2011-07-21  9:43         ` Georg Bauhaus
2011-07-21 15:06           ` Robert A Duff
2011-07-31 15:02             ` BrianG
2011-07-21 21:11           ` Brian Drummond
2011-07-21  7:59     ` Stephen Leake
2011-07-20 15:29   ` okellogg
2011-07-20 16:24     ` Dmitry A. Kazakov
2011-07-20 16:58       ` okellogg
2011-07-20 19:38         ` Dmitry A. Kazakov
2011-07-20 17:27     ` Robert A Duff
2011-07-20 19:14       ` okellogg [this message]
2011-07-20 20:13         ` J-P. Rosen
2011-07-20 21:23           ` Robert A Duff
2011-07-20 21:21         ` Robert A Duff
2011-07-21  8:02         ` Stephen Leake
2011-07-21  8:00     ` Stephen Leake
2011-07-21  7:36   ` Martin
2011-07-22 23:50   ` Randy Brukardt
2011-07-23  2:16     ` tmoran
2011-07-23 15:12     ` Robert A Duff
2011-07-26 21:10       ` Randy Brukardt
2011-07-23  0:01   ` Randy Brukardt
  -- strict thread matches above, loose matches on Subject: below --
1998-04-17  0:00 Should Representation Clauses " Marin David Condic, 561.796.8997, M/S 731-96
     [not found] <3533C3C5.3F25CB91@cacd.rockwell.com>
1998-04-16  0:00 ` Stephen Leake
replies disabled

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