From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Should representation clauses be complete for each bit?
Date: Wed, 20 Jul 2011 10:51:37 -0400
Date: 2011-07-20T10:51:37-04:00 [thread overview]
Message-ID: <wcczkk9ngxy.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 73c10395-ec4f-4a02-b0fc-e35bc14424fa@e18g2000vbx.googlegroups.com
okellogg <okellogg@users.sourceforge.net> writes:
> Picking up an age old thread,
> http://groups.google.com/group/comp.lang.ada/browse_thread/thread/9ab165cd2cc73cb
Wow. 1998.
> IMHO it would be a real gain if we could explicitly mention the unused
> bits in the rep spec.
I think the unused bits should be explicitly declared.
> Reusing the example from the OP,
>
>> type x is record
>> one : boolean;
>> two : boolean;
>> three : boolean;
>> end record;
>> for x use record
>> one at 0 range 0..0;
>> two at 0 range 3..3;
>> three at 0 range 15..15;
>> end record;
>
> What I imagine is something like,
>
> for x use record
> one at 0 range 0 .. 0;
> null at 0 range 1 .. 2; // note reserved word "null"
> two at 0 range 3 .. 3;
> null at 0 range 4 .. 14;
> three at 0 range 15 .. 15;
> end record;
> for x'Size use 16;
>
> The components with "null" would instruct the compiler to fill the
> bits with 0.
How about the following?
package P is
type Bits2 is mod 2**2;
pragma Assert (Bits2'Size = 2);
type Bits11 is mod 2**11;
pragma Assert (Bits11'Size = 11);
type T is
record
One : Boolean;
Gap1 : Bits2; -- must be zero
Tooth : Boolean;
Gap2 : Bits11; -- must be zero
Ree : Boolean;
end record
with Predicate => T.Gap1 = 0 and T.Gap2 = 0;
for T use
record
pragma Complete_Representation;
One at 0 range 0..0;
Gap1 at 0 range 1..2;
Tooth at 0 range 3..3;
Gap2 at 0 range 4..14;
Ree at 0 range 15..15;
end record;
end P;
with Ada.Assertions; use Ada.Assertions;
procedure P.Main is
X : T := (One | Tooth | Ree => True, Gap1 => 0, Gap2 => 0); -- OK
begin
begin
X := T'(One | Tooth | Ree => True, Gap1 => 1, Gap2 => 2); -- Wrong.
exception
when Assertion_Error => null; -- OK
end;
pragma Assert (X = (One | Tooth | Ree => True, Gap1 => 0, Gap2 => 0));
end P.Main;
By the way, I find Ada's representation clauses to be at the wrong
level of abstraction. Why can't I just write a single line of code
that means "put all the components in declaration order with no gaps
in between"?
- Bob
next prev parent reply other threads:[~2011-07-20 14:51 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 [this message]
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
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