comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Size of a pointer to a tagged record
Date: Wed, 4 Dec 2002 17:17:19 GMT
Date: 2002-12-04T17:17:19+00:00	[thread overview]
Message-ID: <wccvg29d7q8.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: asl7s3$qjb$1@pegasus.csx.cam.ac.uk

news01+Steven.Murdoch@cl.cam.ac.uk (Steven Murdoch) writes:

> Thanks for your reply.

You're welcome.

> >> type Parameter is tagged private;
> >> type Parameter_Access is access all Parameter'Class;
> >> 
> >> package Convert is new
> >>      System.Address_To_Access_Conversions(Parameter);
> >> 
> >> addr: System.Address;
> >> param: Parameter_Access;
> >> 
> >> 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?

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 you want to clarify the type (just to make the code more readable),
use a qualified expression, as in "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 *

>... Currently is returns
> a "void *" which I believe is equivalent to a System.Address. What
> would it's type be if it it returned an "Parameter_Access"?
> Is it safe to mark a pragma Import(C) function as returning a
> Parameter_Access?

No, it's not safe.  But interfacing across languages is never safe --
you always have to make sure the sizes of things match.

> ...Would this be a better idea?

I have no opinion either way.

> >You can find out the size of a pointer by writing a little test program
> >that prints out Parmeter_Access'Size, and running it on as many Ada
> >compilers as you can get your hands on.
> 
> 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.

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.

- Bob



  reply	other threads:[~2002-12-04 17:17 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 [this message]
2002-12-04 17:56       ` Steven Murdoch
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