comp.lang.ada
 help / color / mirror / Atom feed
From: kug1977 <kug1977@web.de>
Subject: Re: Access Type
Date: Wed, 29 Dec 2010 00:46:35 -0800 (PST)
Date: 2010-12-29T00:46:35-08:00	[thread overview]
Message-ID: <0cc2d01d-2744-470f-82e9-f7aa1c097783@c39g2000yqi.googlegroups.com> (raw)
In-Reply-To: m2pqsl78wb.fsf@pushface.org

On 29 Dez., 00:52, Simon Wright <si...@pushface.org> wrote:
> kug1977 <kug1...@web.de> writes:
> > For my programm I need a type like System.Address but with a
> > definitive size of 32-bits. So I've create one
>
> >    type t_OFW_vAddress is mod t_Cell_Size;
> >    for t_OFW_vAddress'Size use 32 ;
> >    pragma Assert (t_OFW_vAddress'Size = 32);
> >    pragma Assert (t_OFW_vAddress'Alignment = 4) ;
>
> >    OFW_Null_vAddress : constant t_OFW_vAddress := 0;
>
> You shouldn't need the first Assert, because if the compiler can't
> honour the "for t_OFW_vAddress'Size use 32;" it should refuse the
> compilation.
>
> Similarly, replace the second Assert by "for t_OFW_vAddress'Alignment
> use 4;".
>
> But .. are you using GNAT? because, being built on GCC, its natural
> tendency is to use the same representations as C would. In any case, I
> think you're making things more complicated than they need to be.
>
> Assuming that both your Ada and C compilers are 32-bit (you have big
> problems ahead if they are different!), type System.Address is going to
> be 32-bits and 4-byte aligned anyway.
>
> So why not just use System.Address? (I guess in that case it would make
> sense to assert that System.Address'Size is 32, etc. Though the main
> thing is to be sure that your compilers and system libraries agree!)

I've to give you more information about the project. The thing will be
a bootloader for IEEE1275 aka Open Firmware (OFW) (used in Apple Mac
PPC's). So, my Ada programm is using the OFW client interface which is
defined in the standard usign 32-bit wide Cells on 4-Byte boundaries
some hold natural numbers, others pointer to X but all are 32-bit. So,
the damn thing are not allowed to use 64-Bit wide System.Address.

So, you suggest to use an System.Address, an assert for the 32-bit and
compiler options to make sure every thing is 32-bit? Sounds easy.

> If "type Client_Entry is" just "access procedure", how come it has
> arguments?

OFW need a pointer to the procedure and a pointer to an array which
holds the arguments. OFW will call the procedure with the arguments.
But, you are right, if I have a procedure X without arguments defined,
the call sequence will be without space for that pointer.

> I would define the Entry item by just
>
>    type Chain_CI_Args is record
>       ...
>       Another_Clients_Entry : Client_Entry;
>
> The Arguments part is a bit more tricky. It's a bad idea to try passing
> indefinite items like a t_OFW_Buffer via a single thin pointer; GNAT
> does it using a two-component (fat) pointer. You'll need either to pass
> another element saying how many bytes there are in the Arguments, or to
> have it terminated somehow.

There's a length field in the structure I pass to OFW. SO that thing
is handled.

>
> I'd then try
>
>    type Chain_CI_Args is record
>       ...
>       Another_Clients_Entry : Client_Entry;
>       Another_Clients_Arguments : System.Address;
>       Another_Clients_Args_Len : Integer;
>       ...
>
> so you'd write
>
>       ...
>       Another_Clients_Entry => Another_Clients_Entry,
>       Another_Clients_Arguments =>
>          Another_Clients_Arguments
>       (Another_Clients_Arguments'First)'Address,
>       Another_Clients_Args_Len => Another_Clients_Arguments'Length,
>       ...
>
> which does assume that the elements of t_OFW_Buffer are contiguous and
> that Integer is OK to be passed in a C struct (both pretty good guesses
> for any normal compiler, I'd say).
>
> > PS: I know, that this isn't something a beginner in Ada should start
> > with, but I like to finnish porting this from C to Ada.
>
> You start from wherever you happen to be!
>
> Hope that helps; my laptop's battery is running out & it's bedtime!

Simon, I really appreciate your help and hope you don't stop. Learned
a lot in the last days. I start learning Ada with to many knowledge in
low level programming (M68k und PPC ASM) but less knowledge in high
level languages. So, most of the time I've a good understanding what I
want in the end, but get confused by my own demand on programming type
save.

King regards, kug1977



  reply	other threads:[~2010-12-29  8:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-24 16:36 Access Type kug1977
2010-12-24 17:30 ` Robert A Duff
2010-12-24 20:59   ` kug1977
2010-12-24 22:06     ` Simon Wright
2010-12-27  1:50     ` Ludovic Brenta
2010-12-27 12:29       ` Simon Wright
2010-12-27 17:53         ` Ludovic Brenta
2010-12-27 18:15           ` Simon Wright
2010-12-27 20:03             ` Pascal Obry
2010-12-28 20:08               ` kug1977
2010-12-28 23:52                 ` Simon Wright
2010-12-29  8:46                   ` kug1977 [this message]
2010-12-29 15:18                     ` Simon Wright
2010-12-29 15:27                       ` Ludovic Brenta
replies disabled

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