comp.lang.ada
 help / color / mirror / Atom feed
* Record representation : components order
@ 2009-07-04 21:08 Hibou57 (Yannick Duchêne)
  2009-07-05  3:14 ` Hibou57 (Yannick Duchêne)
  2009-07-05 14:10 ` Stephen Leake
  0 siblings, 2 replies; 13+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2009-07-04 21:08 UTC (permalink / raw)


Good evening to all (evening time here - good morning for the others),

I was looking back at the RM section 13, “ Representation issues ” for
records.

First of all, I noticed somehing I had forgot, with an nice example in
annotion

> 44    For every subtype S:
> 45    S'Size If S is definite, denotes the size [(in bits)] that the implementation would
>         choose for the following objects of subtype S:
> 46    A record component of subtype S when the record type is packed.
> 47    The formal parameter of an instance of Unchecked_Conversion that converts from
>        subtype S to some other subtype.

If a packed record .... or a formal parameter of an unchecked
conversion. To not to be forgotten, otherwise the implementation is
not required to enforce the size attribute given to a subtype, unlinke
when the size attribute is given to an instance of a subtype.

The annotation later:

> 55.j  The fact that the size of an object is not necessarily the same as its subtype can
>         be confusing:
> 55.k  type Device_Register is range 0..2**8 - 1;
>         for Device_Register'Size use 8; -- Confusing!
>         My_Device : Device_Register;
>         for My_Device'Address use To_Address(16#FF00#);

55.l     The programmer might think that My_Device'Size is 8, and that
My_Device'Address
>         points at an 8-bit location. However, this is not true. In Ada 83 (and in Ada 95),
>        My_Device'Size might well be 32, and My_Device'Address might well point at the high-order
>        8 bits of the 32-bit object, which are always all zero bits.

Indeed, confusing

But the question is not there (I point it for concerned people)

Going on in section 13, I did no see about record components order
apart the “ at X range Y .. Z ” which directly specify it.

But looking at some design in some place in the web, people usually do
this way : define some component type with a size clause, and then,
just use these type in some records, most of time, without using any “
at X range Y .. Z ” . But to me, this seems to be unsafe, beceause
components order is not guaranted to be that of the declaration.

Is there something I missed ? I was thinking that an Ada compiler was
allowed to reorder component of a record if it can helps some
efficiency (I know at least a case, where this could help on some old
machine) and thus that the declaration is a the declaration and the
physical repsentation is not required to match what one might suppose,
unless explicitely specified.

But I did not see anything which assert that simply using sized types
and design records with it and a pragma pack without any “ at range ”
can ensure this.

I did not see about the effect of a pragma convention on a
representation. Is it related ?



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2009-07-10  5:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-04 21:08 Record representation : components order Hibou57 (Yannick Duchêne)
2009-07-05  3:14 ` Hibou57 (Yannick Duchêne)
2009-07-05 10:16   ` sjw
2009-07-06  7:33     ` Stephen Leake
2009-07-07 19:37       ` sjw
2009-07-09  9:28         ` Stephen Leake
2009-07-09 19:16           ` sjw
2009-07-10  5:26             ` Stephen Leake
2009-07-06  7:29   ` Stephen Leake
2009-07-06  8:07   ` Jean-Pierre Rosen
2009-07-05 14:10 ` Stephen Leake
2009-07-06  2:57   ` Hibou57 (Yannick Duchêne)
2009-07-06  8:27     ` Jacob Sparre Andersen

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