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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bb163c965c676b88 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.66.85.136 with SMTP id h8mr1507595paz.46.1348306337989; Sat, 22 Sep 2012 02:32:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.238.201 with SMTP id vm9mr1987338pbc.6.1348306337972; Sat, 22 Sep 2012 02:32:17 -0700 (PDT) Path: t10ni7124914pbh.0!nntp.google.com!4no7019032pbn.1!postnews.google.com!k3g2000pbr.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 22 Sep 2012 02:32:17 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: k3g2000pbr.googlegroups.com; posting-host=123.2.70.40; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le NNTP-Posting-Host: 123.2.70.40 References: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1,gzip(gfe) Message-ID: Subject: Re: Endianness and Record Specification From: Robin Vowels Injection-Date: Sat, 22 Sep 2012 09:32:17 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-09-22T02:32:17-07:00 List-Id: On Sep 22, 4:16=A0am, awdorrin wrote: > I have been reading over google searches all day and I feel like I'm miss= ing something here. > > Is there a straight forward method to use Standard'Default_Bit_Order to d= efine a specification for a record, that will work on either a Little Endia= n or Big Endian system? > > For instance, I have a 16-bit field that is comprised of 5 bit-fields: > Reserved: =A0 =A0 1 bit > Error Flag: =A0 1 bit > Word Count: =A0 6 bits > Bus Id: =A0 =A0 =A0 1 bit > Message Type: 7 bits > > So, 0x0401 is [0000 0100 0000 0001] or [0][0][000100][0][0000001] > Word Count =3D 4, Message Type =3D 1 > > On a Big Endian system the record is defined as: > > type TW_REC is record > =A0 Message =A0 : Integer; > =A0 BusId =A0 =A0 : Integer; > =A0 WordCount : Integer; > =A0 Error =A0 =A0 : Integer; > =A0 Reserved =A0: Integer; > end record > for TW_REC use record > =A0 Reserved =A0at 0 range 0..0; > =A0 Error =A0 =A0 at 0 range 1..1; > =A0 WordCount at 0 range 2..7; > =A0 BusId =A0 =A0 at 1 range 0..0; > =A0 Message =A0 at 1 range 1..7; > end record; > > Now, I know I can rewrite this on a Little Endian system to: > for TW_REC'Bit_Order use System.High_Order_First; > for TW_REC use record > =A0 Reserved =A0at 1 range 0..0; > =A0 Error =A0 =A0 at 1 range 1..1; > =A0 WordCount at 1 range 2..7; > =A0 BusId =A0 =A0 at 0 range 0..0; > =A0 Message =A0 at 0 range 1..7; > end record; > > Taking advantage of the High_Order_First flag to keep the bit ordering th= e same, > but is there a way to either calculate the byte position, or 'conditional= ly compile' the right record specification, depending on the system on whic= h it is being compiled? > > At first I was thinking I could do: > > if Standard'Default_Bit_Order =3D 1 then > =A0 -- defined Little endian rec spec > else > =A0 -- define Bit endian rec spec > end if; > > But, the compiler doesn't let me do that... :-) > > I would think I should be able to somehow use the > Default_Bit_Order to define some sort of relative byte position, > depending on the system endianness, but I'm drawing a blank > and hoping someone might have a quick example they could provide. This won't help your problem, but PL/I bit strings are stored in correct order regardless of big-endian or little-endian machine on which the program runs. The memory image is identical for both machine types.