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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,ea4b92bb88a43e50 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-23 04:18:54 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!213.56.195.71!fr.usenet-edu.net!usenet-edu.net!proxad.net!feeder2-1.proxad.net!nnrp1.proxad.net.POSTED!not-for-mail Message-ID: <3B349822.9D2F1974@free.fr> From: Carbonne Damien X-Mailer: Mozilla 4.75 [fr] (X11; U; Linux 2.2.17-21mdk i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada records and byte order References: Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Date: Sat, 23 Jun 2001 11:18:53 GMT NNTP-Posting-Host: 212.27.46.228 X-Complaints-To: abuse@proxad.net X-Trace: nnrp1.proxad.net 993295133 212.27.46.228 (Sat, 23 Jun 2001 13:18:53 CEST) NNTP-Posting-Date: Sat, 23 Jun 2001 13:18:53 CEST Organization: Guest of ProXad - France Xref: archiver1.google.com comp.lang.ada:9055 Date: 2001-06-23T11:18:53+00:00 List-Id: Karl Ran a �crit : > > Here is the code ... > > procedure test is > > subtype BYTE is Integer range 0 .. 2 ** 8 - 1; Add: for BYTE'size use 8; > > subtype WORD12 is integer range 0 .. 2 ** 12 - 1; Add for WORD'Size use 12; > > subtype WORD4 is integer range 0 .. 2 ** 4 - 1; Add: for WORD4'Size use 4; > > > type My_rec is > record > A : BYTE; > B : WORD12; > C : WORD4; > end record; > > for My_rec use > record > A at 0 range 0 .. 7; > B at 1 range 0 .. 11; > C at 2 range 0 .. 3; Change previous line to: C at 1 range 12 .. 15; or C at 2 range 4 .. 7; > > end record; Add: for My_rec'Size use 24; > > > Abc : My_Rec; > > begin > Abc.b := 16#123#; > ... > end test; > > ... which fails to compile whith GNAT on a (low-endian) i386: > test.adb:31:10: component "C" overlaps "B" at line 30 > The message seems quite explicit here ! > > Is there an Ada like (TM) solution for this kind of (byte order) problem? What you have is not a byte order problem. You may have one if the program with which you wrote the file and the one you are writing in Ada are run on targets with different byte orders. This can not be deduced from your message. For Byte order problem, I remember having seen something (quite complexe) on this thread some times ago, but I don't remember when and who posted it. Anyway, a compiler may refuse certain representation clauses and thus, there may be some portability problems in this area. GNAT should accept what you want in that case, unless there is a real error like here. Pragmatically, from what I have read on thsi subject, major compilers accept standard size clauses (powers of 2). There are always limits ! The Ada syntax is different from C/C++ one for bitfields where you only specify the size (length) of each field, whereas in Ada you specify bit bounds (first and last) counted from an offset (defined in Memory_Unit I think). Regards Damien