From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a415d3a613d86a4e X-Google-Attributes: gid103376,public From: Mats Weber Subject: Re: GNAT'Object_Size Date: 1997/12/08 Message-ID: <348C1957.3F4352F4@elca-matrix.ch>#1/1 X-Deja-AN: 296295543 References: <662cs9$b34$1@newman.pcisys.net> <663j9f$e1l@mtinsc02.worldnet.att.net> <3485D2AE.3F54@hso.link.com> <3486E716.FD325298@elca-matrix.ch> Organization: ELCA Matrix SA Reply-To: Mats.Weber@elca-matrix.ch Newsgroups: comp.lang.ada Date: 1997-12-08T00:00:00+00:00 List-Id: 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.