comp.lang.ada
 help / color / mirror / Atom feed
* Record component positions always constant?
@ 1996-05-26  0:00 Dale Stanbrough
  1996-05-26  0:00 ` Robert Dewar
  0 siblings, 1 reply; 2+ messages in thread
From: Dale Stanbrough @ 1996-05-26  0:00 UTC (permalink / raw)



Will the positions of the components in a record (for a given
subtype) remain constant even in the presence of fields whose
lengths depend on a discriminant (excluding of course variant
records) for all (likely) Ada implementations?

Dale




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

* Re: Record component positions always constant?
  1996-05-26  0:00 Record component positions always constant? Dale Stanbrough
@ 1996-05-26  0:00 ` Robert Dewar
  0 siblings, 0 replies; 2+ messages in thread
From: Robert Dewar @ 1996-05-26  0:00 UTC (permalink / raw)



Dale asked:

"Will the positions of the components in a record (for a given
subtype) remain constant even in the presence of fields whose
lengths depend on a discriminant (excluding of course variant
records) for all (likely) Ada implementations?"

The answer is NO for all likely Ada implementations, a subtype is
required to take only as much space as it needs. One can imagine
an imlementatoin that uses hidden heap pointers for variable length
components depending on discriminants, but in practice virtually all
(all?) implementations store the variable length field in place. Some
implementations store extra offset components to help them find their
way past such components (old Alsys technology does this in the absence
of some pragma (I forget the details of he pragma). Other implementations
(Dec, GNAT, Alsys with that pragma), recompute their way past the
variable length fields from the discriminant values on each reference.

To give a very specific example:

   type R (N : Natural) is record
      S1 : String (1 .. N);
      S2 : String (1 .. N);
   end record;

the offset of component S2 will typically vary with the value of N.

There is an ACVC test that ensures that no implementation uses
allocate-the-maximum for such individual fields.





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

end of thread, other threads:[~1996-05-26  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-26  0:00 Record component positions always constant? Dale Stanbrough
1996-05-26  0:00 ` Robert Dewar

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