comp.lang.ada
 help / color / mirror / Atom feed
From: news01+Steven.Murdoch@cl.cam.ac.uk (Steven Murdoch)
Subject: Re: Size of a pointer to a tagged record
Date: 4 Dec 2002 17:56:01 GMT
Date: 2002-12-04T17:56:01+00:00	[thread overview]
Message-ID: <aslfjh$1vc$1@pegasus.csx.cam.ac.uk> (raw)
In-Reply-To: wccvg29d7q8.fsf@shell01.TheWorld.com

In article <wccvg29d7q8.fsf@shell01.TheWorld.com>,
 Robert A Duff <bobduff@shell01.TheWorld.com> writes:

>> >> addr:=Get_Void_Pointer; --Void* from C
>> >> param:=Parameter_Access(User_Data_Convert.To_Pointer(Address));
>> >         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> >That code is wrong, so I'm not sure what you mean.
>> 
>> Well it compiles.
>
>I see nothing called User_Data_Convert in the above code.
>Perhaps you meant Convert?

Yes, sorry (I forgot to simplify that when I pasted it in)

>Also, the result of To_Pointer is Parameter_Access,
>so you don't need to additionally convert to Parameter_Access
>(by saying "Parameter_Access(...)").  That would compile,
>but it's silly to convert from a type to itself.

If I take out the "Parameter_Access(...)" I get the following error message:
lua.adb:172:35: expected type "Parameter_Access" defined at lua.ads:13
lua.adb:172:35: found type "System.Address_To_Access_Conversions.Object_Pointer" from instance at line 36
so it seems that the result of To_Pointer is Object_Pointer rather than Parameter_Access.

>> >Anyway, why not declare Get_Void_Pointer to return the access type?
>> >I see no need for Address_To_Access_Conversions.
>> 
>> What would it's type in C be in that case?
>
>void *

OK, I will try that, it would clean up my code substantially.

>> On GNAT 3.13p it is 32 (I assume bytes) which is indeed the same
>> size as System.Address.
>
>'Size is in bits, not bytes.

Sorry, that's what I meant. 32 byte addresses would be a rather larger
address space that would be necessary :-)

>One thing you might think about is taking 'Size on the Ada side,
>converting that to bytes (using System.Storage_Unit), and passing
>that to the C code at some point.  The C code might be able to
>use that size, or else assert that it is correct.

I will try that too, the size is set during run time so there
should not be any problem setting it. IIRC Malloc takes a number of
octets so I could use a variant of Jeff Carters suggestion such as
(Parameter_Access'Size + 7) / 8
This should be the right thing to pass in, even if Storage_Unit is not 8

Thanks again,
Steven Murdoch.



  reply	other threads:[~2002-12-04 17:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-04 14:01 Size of a pointer to a tagged record Steven Murdoch
2002-12-04 15:16 ` Robert A Duff
2002-12-04 15:44   ` Steven Murdoch
2002-12-04 17:17     ` Robert A Duff
2002-12-04 17:56       ` Steven Murdoch [this message]
2002-12-04 19:10         ` Robert A Duff
2002-12-07  6:55         ` David Thompson
2002-12-04 20:27       ` Simon Wright
2002-12-04 18:11     ` tmoran
2002-12-04 17:05 ` Jeffrey Carter
replies disabled

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