comp.lang.ada
 help / color / mirror / Atom feed
From: "Marc A. Criley" <mcNOSPAM@mckae.com>
Subject: Re: What is correct way to pack records
Date: Thu, 18 Nov 2004 11:04:23 -0600
Date: 2004-11-18T11:04:23-06:00	[thread overview]
Message-ID: <30430rF2qcqp0U1@uni-berlin.de> (raw)
In-Reply-To: 3fc90377.0411171620.7a3bcfd9@posting.google.com

"Warren O. Merrill" <wom@inel.gov> wrote:

> I want my record structures to byte align (for compatibility with
> existing files).  I know about using the record representation clause
> to lay them out.  I have a LOT of these to do and just wondering if
> any of the pragmas would be guaranteed to byte align my fields but NOT
> change the order of the fields to do it (NOTE THAT IS IMPORTANT!!!!!).
>
> So instead of:
>
> type MyRec is record
>   Fld1 : character;
>   Fld2 : character;
>   Fld3 : character;
> end record;
>
> for MyRec use record
>   Fld1 at 0 range 0 .. 7;
>   Fld2 at 1 range 0 .. 7;
>   Fld3 at 2 range 0 .. 7;
> end record;
>
> is there a pragma (or other method) that will do the same thing
> GUARANTEED not to change the field order to accomplish the packing
> without having to write all these record representation clauses?

Yes.  Though it carries some baggage that may or may not matter to you.

pragma Convention(C, MyRec);

pragma Convention with the C convention-identifier will ensure that record
layout corresponds to that used for a comparable C construct--meaning that
it won't change the order, and the fields will occupy the same size,
alignment, and offsets as if they were declared using comparable C
definitions.  Note that pad bytes may be inserted to maintain C-conformant
field alignments.  If you choose to do this, you should verify that the
record layout conforms to the file record format that you'll be reading.

Marc A. Criley
McKae Technologies
www.mckae.com





  parent reply	other threads:[~2004-11-18 17:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-18  0:20 What is correct way to pack records Warren O. Merrill
2004-11-18  0:27 ` Jeffrey Carter
2004-11-18  6:50 ` Martin Dowie
2004-11-18 12:37 ` Stephen Leake
2004-11-18 17:04 ` Marc A. Criley [this message]
2004-11-18 17:31   ` Jeffrey Carter
2004-11-18 18:00     ` Marc A. Criley
2004-11-19  3:08       ` Steve
2004-11-19 12:44         ` Frank J. Lhota
2004-11-19 13:28           ` Marc A. Criley
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox