comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: A Record Interpretation of an Array
Date: Tue, 29 May 2001 03:29:18 GMT
Date: 2001-05-29T03:29:18+00:00	[thread overview]
Message-ID: <3B131780.656B8B93@acm.org> (raw)
In-Reply-To: 3B12C9E0.5E9B06C8@earthlink.net

"Marc A. Criley" wrote:
> 
> I know what I'm going to be asking about is not defined by the language,
> is non-portable, is implementation defined, etc.  I'm just looking to
> gather some thoughts and opinions here.
> 
> Consider a plain, simple, fixed-length array of some type--no variants,
> tagged types, unconstrained anythings, packing pragmas or
> specifications.  Just your plain 'ole basic array.  For example, an
> array (1..5) of Integer.
> 
> If I wanted to access the contents of this array as a analogous record,
> I could declare something like:
> 
>   type Record_View is
>     record
>       Field1 : Integer;
>       Field2 : Integer;
>       Field3 : Integer;
>       Field4 : Integer;
>       Field5 : Integer;
>     end record;
> 
> and do an Unchecked_Conversion between the array type and this record
> type.
> 
> Is it reasonable to think this conversion (going either way) would give
> sensible results?  Is there a stronger basis for that answer than a
> naive "reasonable to think"?

This is reasonable. I can't see any reason why they would not be
represented internally the same way. If you're willing to add some
representation information to the record type, you could probably check
this (for Record_View'Size use Array_Type'Size;). If you can also put
some representation information on the array type you can ensure this.

> 
> What if the array element type was of a record type, whose 'size
> indicated an odd number of bytes?  My experience has been that arrays of
> such types pad out the elements, and so could one also reasonably expect
> the analogous record view to equivalently pad out each such field?
> 

Here you're getting onto thinner ice. It would be better to require
identical representations here. Even if you can't add representation
clauses to the array, you could still add them to a derived type:

type Array_With_Representation is new Array_Type;
for Array_With_Representation'Component_Size use ...;
pragma Pack (Array_With_Representation);
for Array_With_Representation'Size use ...;

Lay out your Record_View type to use the same representation, then
convert your array value to Array_With_Representation before unchecked
converting it Record_View:

To_Record_View (Array_With_Representation (Array_Value) );

Multidimensional arrays are just a further wrinkle to this idea.

-- 
Jeff Carter
"I blow my nose on you."
Monty Python & the Holy Grail



  reply	other threads:[~2001-05-29  3:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-28 22:53 A Record Interpretation of an Array Marc A. Criley
2001-05-29  3:29 ` Jeffrey Carter [this message]
2001-05-29 13:34 ` Ted Dennison
2001-05-29 14:16 ` Marin David Condic
2001-05-31  0:55 ` Keith Thompson
2001-05-31 12:47   ` Marc A. Criley
2001-06-01  1:22     ` Keith Thompson
2001-06-01  0:14 ` Mark
2001-06-01  8:45   ` Ehud Lamm
2001-06-01 12:39   ` Marc A. Criley
2001-06-01 18:20     ` Tucker Taft
replies disabled

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