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-7-bit X-Google-Thread: 103376,ea4b92bb88a43e50,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-23 03:15:23 PST Path: archiver1.google.com!newsfeed.google.com!postnews1.google.com!not-for-mail From: karlran1234@yahoo.com (Karl Ran) Newsgroups: comp.lang.ada Subject: Ada records and byte order Date: 23 Jun 2001 03:15:23 -0700 Organization: http://groups.google.com/ Message-ID: NNTP-Posting-Host: 217.49.112.51 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 993291323 11582 127.0.0.1 (23 Jun 2001 10:15:23 GMT) X-Complaints-To: groups-support@google.com NNTP-Posting-Date: 23 Jun 2001 10:15:23 GMT Xref: archiver1.google.com comp.lang.ada:9054 Date: 2001-06-23T10:15:23+00:00 List-Id: Hi there, I've a question about Ada records: I have to read a binary file from disk which was written by another program. The record size is fixed: 3 bytes The file structure looks like this: |byte 1 | |byte 2 | |byte 3 | |byte 4... aaaa.aaaa.bbbb.bbbb.bbbb.cccc | aaaa.a..... M L M L M L S S S S S S B B B B B B a: 8 bits b: 12 bits c: 4 bits Here is the code ... procedure test is subtype BYTE is Integer range 0 .. 2 ** 8 - 1; subtype WORD12 is integer range 0 .. 2 ** 12 - 1; subtype WORD4 is integer range 0 .. 2 ** 4 - 1; 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; end record; 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 Is there an Ada like (TM) solution for this kind of (byte order) problem? Thanks, Karl