TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Classic View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Mats Weber <[log in to unmask]>
Wed, 4 Nov 1998 15:48:03 +0100
text/plain (54 lines)
Steven Deller wrote:
> Mats,
> I find GNAT's object_size interesting and may push for this to be added to
> Rational's Apex.  However, I find the definition lacking in precision,
> making it unclear what to ask for.
> My interpretation of the GNAT documentation is that the intention for
> typename'object_size is to be equivalent to declaring an object of typename
> and taking 'size of that object.

No, not exactly. If the type has discriminants with default values, then
X'Size will usually return the size of the current variant, but
T'Object_Size will return the size of the largest variant.

> My problem is that GNAT does not appear to follow that definition.
> Specifically, take the example of
>   type x record is
>     i : integer ;
>     b : short_short_integer ;
>   end record ;
> According to GNAT documentation, x'object_size should be 64.  But that would
> seem to depend on what object follows the object declaration.  For example,
> suppose we have the declarations:
>    objectx : x ;
>    objectssi : short_short_integer ;
> Then you would find, at least on Apex, that objectssi started 5 bytes after
> objectx, since objectx only actually occupies 5 bytes and objectssi only
> needs byte alignment.  It seems to me that if an object may only occupy 5
> bytes, then object_size should be 40, not 64. With the GNAT definition, one
> could construct a case where the sum of object_size for components of the
> record was greater than object_size for the record -- that seems
> counter-intuitive.

I don't know. Have you tried the example on GNAT ? Maybe someone from
ACT could comment on that ?

> For your example, T'alignment has no importance on Apex (and as I said, I
> still fail to see why it is important on GNAT).  You need only take
> T'base'size and round it up to the next byte to find the size of an object
> of that type.  Since your code already uses 'base and already does rounding
> up, you need only change "object_size" to "size" to have it work on Apex.
>  Hence my continuing confusion about why object_size is needed at all.

I think part of the confusion comes from the 'Size stuff in the RM. RM
13.3(43) says that a size _clause_ must be supported if it is a multiple
of the alignment. But does that mean that 'Size should also _return_
something that is a multiple of the alignment ? I'd appreciate a comment
from someone who knows the intent of the standard.