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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9ed448b3da4e578c X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Interfacing Ada to C Date: 1997/05/30 Message-ID: #1/1 X-Deja-AN: 245162653 References: <5mjvk9$sm7$1@luna.ffi.no> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 1997-05-30T00:00:00+00:00 List-Id: In article , Samuel Tardieu wrote: > type My_Natural is range 0 .. 15; > for My_Natural'Size use 4; The 'Size clause should not be necessary. My_Natural'Size = 4 by default. At least this is true for a compiler that conforms to the SP Annex -- without that, most of chapter 13 means nothing anyway. > type R is record > A, B : My_Natural; > end record; > pragma Pack (R); > for R'Size use 8; > >If you do: > > My_R : aliased constant R := (1, 2); > >then My_R will be represented in memory by a single byte containing >00010010 (or 00100001, depending on the endianness). That's misleading. The RM says that it will fit in 8 bits. The RM says nothing about the order of the components. The order need not have anything to do with endianness -- it's up the whim of the compiler writer. Consider a record with three components -- there are 6 possible orders to lay them out in memory (assuming the compiler isn't doing anything really weird, like splitting components into pieces), and the compiler can choose any one of those 6. Some of those orders may be more efficient than others. I would like my compiler to choose an efficient order (unless I do pragma Convention(C) or whatever, in which case I want the order to match the source code). I want to write my record type in some logical order, without worrying too much about what the most efficient layout is. This is true whether or not I choose to use pragma Pack. - Bob