comp.lang.ada
 help / color / mirror / Atom feed
From: Mats Weber <Mats.Weber@elca-matrix.ch>
Subject: Re: GNAT'Object_Size
Date: 1997/12/08
Date: 1997-12-08T00:00:00+00:00	[thread overview]
Message-ID: <348C1957.3F4352F4@elca-matrix.ch> (raw)
In-Reply-To: 3486E716.FD325298@elca-matrix.ch


I wrote:

> And also generalize 'Object_Size so that it works on objects as well as types,
> and returns the size actually allocated for an object, so that the following
> code can be made to work:
> 
> generic
>    type T (<>) is private;
> procedure Receive (M : out T) is
> 
>    function Read (FD     : Integer;
>                   Buffer : System.Address;
>                   Count  : Integer) return Integer;
> 
>    pragma Import(C, Read);
> 
>    Length : Integer;
> 
> begin
>    Length := Read(Socket,
>                   M'Address,
>                   M'Object_Size / System.Storage_Unit);
> end;
> 
> Using 'Size in this situation is not portable because some compilers take it
> to mean the size of the current value, not that of the object (which can be
> different in the case of unconstrained types).

After a discussion with Robert Dewar, the above approach cannot be made to
work in all cases because a subprogram does not in general know the size of
its actual parameters, so that implementing 'Object_Size for objects would
require an extra parameter, which is an unnecessary overhead most of the time.

Some Ada 83 compilers (Verdix in this case) do smart things for 'Size applied
to parameters: they return the value size for mode in parameters, and the
object size for mode out parameters (how they do it I don't know), which is
exactly what is needed to solve the above problem, but doesn't help when
porting to other compilers.




  reply	other threads:[~1997-12-08  0:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-03  0:00 Ada Enumerations Jeffrey Harris
1997-12-03  0:00 ` James S. Rogers
1997-12-03  0:00   ` Robert Dewar
1997-12-03  0:00     ` Stanley R. Allen
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` Ada Enumerations Matthew Heaney
1997-12-04  0:00         ` Stanley R. Allen
1997-12-07  0:00           ` Keith Thompson
1997-12-07  0:00             ` Robert Dewar
1997-12-08  0:00               ` Keith Thompson
1997-12-07  0:00                 ` Matthew Heaney
1997-12-11  0:00                   ` John G. Volan
1997-12-07  0:00             ` Matthew Heaney
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-05  0:00         ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-08  0:00         ` Mats Weber [this message]
1997-12-10  0:00           ` GNAT'Object_Size Robert Dewar
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` Ada Enumerations Robert Dewar
1997-12-04  0:00         ` Stanley R. Allen
1997-12-18  0:00           ` Wes Groleau
1997-12-04  0:00 ` Stephen Leake
1997-12-04  0:00   ` Matthew Heaney
1997-12-04  0:00     ` Robert Dewar
1997-12-06  0:00       ` Jean-Pierre Rosen
1997-12-06  0:00         ` Making Predefined Operators Abstract Matthew Heaney
replies disabled

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