From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f7c38a023cf370dc X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!panix!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Should representation clauses be complete for each bit? Date: Wed, 20 Jul 2011 10:51:37 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <73c10395-ec4f-4a02-b0fc-e35bc14424fa@e18g2000vbx.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1311173498 9415 192.74.137.71 (20 Jul 2011 14:51:38 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 20 Jul 2011 14:51:38 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:achGutfweGjdJfq3qZplWwsmcis= Xref: g2news1.google.com comp.lang.ada:20237 Date: 2011-07-20T10:51:37-04:00 List-Id: okellogg 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