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: a07f3367d7,f7c38a023cf370dc X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!g16g2000yqg.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Should representation clauses be complete for each bit? Date: Thu, 21 Jul 2011 00:36:22 -0700 (PDT) Organization: http://groups.google.com Message-ID: <22182456-d63d-4da4-aa1b-fa67886bee77@g16g2000yqg.googlegroups.com> References: <73c10395-ec4f-4a02-b0fc-e35bc14424fa@e18g2000vbx.googlegroups.com> NNTP-Posting-Host: 20.133.0.8 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1311233782 13218 127.0.0.1 (21 Jul 2011 07:36:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 21 Jul 2011 07:36:22 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g16g2000yqg.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALERCFNK X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20100101 Firefox/6.0,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20254 Date: 2011-07-21T00:36:22-07:00 List-Id: On Jul 20, 3:51=A0pm, Robert A Duff wrote: > okellogg writes: > > Picking up an age old thread, > >http://groups.google.com/group/comp.lang.ada/browse_thread/thread/9ab... > > Wow. =A0 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, > > >> =A0 =A0type x is record > >> =A0 =A0 =A0one : boolean; > >> =A0 =A0 =A0two : boolean; > >> =A0 =A0 =A0three : boolean; > >> =A0 =A0end record; > >> =A0 =A0for x use record > >> =A0 =A0 =A0one =A0 at 0 range 0..0; > >> =A0 =A0 =A0two =A0 at 0 range 3..3; > >> =A0 =A0 =A0three at 0 range 15..15; > >> =A0 =A0end record; > > > What I imagine is something like, > > > for x use record > > =A0 =A0one =A0 at 0 range 0 .. 0; > > =A0 =A0null =A0 at 0 range 1 .. 2; =A0 =A0// note reserved word "null" > > =A0 =A0two =A0 at 0 range 3 .. 3; > > =A0 =A0null =A0 at 0 range 4 .. 14; > > =A0 =A0three 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 > =A0 =A0type Bits2 is mod 2**2; > =A0 =A0pragma Assert (Bits2'Size =3D 2); > =A0 =A0type Bits11 is mod 2**11; > =A0 =A0pragma Assert (Bits11'Size =3D 11); > > =A0 =A0type T is > =A0 =A0 =A0 record > =A0 =A0 =A0 =A0 =A0One : Boolean; > =A0 =A0 =A0 =A0 =A0Gap1 : Bits2; -- must be zero > =A0 =A0 =A0 =A0 =A0Tooth : Boolean; > =A0 =A0 =A0 =A0 =A0Gap2 : Bits11; -- must be zero > =A0 =A0 =A0 =A0 =A0Ree : Boolean; > =A0 =A0 =A0 end record > =A0 =A0 =A0 =A0 with Predicate =3D> T.Gap1 =3D 0 and T.Gap2 =3D 0; > > =A0 =A0for T use > =A0 =A0 =A0 record > =A0 =A0 =A0 =A0 =A0pragma Complete_Representation; > =A0 =A0 =A0 =A0 =A0One at 0 range 0..0; > =A0 =A0 =A0 =A0 =A0Gap1 at 0 range 1..2; > =A0 =A0 =A0 =A0 =A0Tooth at 0 range 3..3; > =A0 =A0 =A0 =A0 =A0Gap2 at 0 range 4..14; > =A0 =A0 =A0 =A0 =A0Ree at 0 range 15..15; > =A0 =A0 =A0 end record; > end P; > > with Ada.Assertions; use Ada.Assertions; > procedure P.Main is > =A0 =A0X : T :=3D (One | Tooth | Ree =3D> True, Gap1 =3D> 0, Gap2 =3D> 0)= ; -- OK > begin > =A0 =A0begin > =A0 =A0 =A0 X :=3D T'(One | Tooth | Ree =3D> True, Gap1 =3D> 1, Gap2 =3D>= 2); -- Wrong. > =A0 =A0exception > =A0 =A0 =A0 when Assertion_Error =3D> null; -- OK > =A0 =A0end; > =A0 =A0pragma Assert (X =3D (One | Tooth | Ree =3D> True, Gap1 =3D> 0, Ga= p2 =3D> 0)); > end P.Main; > > By the way, I find Ada's representation clauses to be at the wrong > level of abstraction. =A0Why 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 A bit like Telegen2's "pragma Preserve_Layout" (if my memory hasn't rusted too much)?... -- Martin