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,e4d318dc27be1451 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Pragma pack Date: 1997/03/17 Message-ID: #1/1 X-Deja-AN: 226137001 References: <01IGC5R855Z6001KU2@EMAIL.AZ.HONEYWELL.COM> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-03-17T00:00:00+00:00 List-Id: In article <01IGC5R855Z6001KU2@EMAIL.AZ.HONEYWELL.COM>, "C. Berg (602) 436-5290" wrote: >I have some questions for the list Ada gods regarding the use of >pragma pack (this is from Ada '83 land). > >If you have a record similar to the following: > > type blah is record > field_1 : field_1_type; > field_2 : field_2_type; > > end record; > >What is the difference (to an individual record like this) between >employing a pragma pack on this record alone, without packing its >component fields, and not using a pack at all? For example, will >a variable declared to be of this record type be the exact same size >with only the "highest" level pack as with no packs at all? The idea is that pragma Pack remove the gaps between the components; it has nothing to say about the components. It's more clear thinking about a packed array: the gaps between the components are "minimized," but the pragma has no effect on the components themselves. (You'll require separate representation clause for the array components.) If you're just optimizing for space, then you can pragma Pack the record. But if you require a specific representation, then you must use a representation clause. And of course, the use of pragma Pack definately _does_ affect the size of the record. (Note that in the case of a packed array of components whose size is 1, the RM does guarantee that the bits occupy contiguous bit positions; ie there are no gaps. This is the only time when pragma Pack specifies a represention.) Matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271