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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,17f2366fc6172420 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!c39g2000yqi.googlegroups.com!not-for-mail From: kug1977 Newsgroups: comp.lang.ada Subject: Re: Access Type Date: Wed, 29 Dec 2010 00:46:35 -0800 (PST) Organization: http://groups.google.com Message-ID: <0cc2d01d-2744-470f-82e9-f7aa1c097783@c39g2000yqi.googlegroups.com> References: <8d8e1094-d021-4456-85fb-bbb2f3911334@m7g2000vbn.googlegroups.com> <3af2d3d1-ede9-4255-a31b-c5f66c6cee2e@c2g2000yqc.googlegroups.com> <87hbe0m1be.fsf@ludovic-brenta.org> <878vzbm7ah.fsf@ludovic-brenta.org> <4D18F124.1050005@obry.net> <76b6b4aa-201c-412d-93de-d22b532fde3f@w17g2000yqh.googlegroups.com> NNTP-Posting-Host: 80.81.9.126 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1293612395 12455 127.0.0.1 (29 Dec 2010 08:46:35 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 29 Dec 2010 08:46:35 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c39g2000yqi.googlegroups.com; posting-host=80.81.9.126; posting-account=3ciIaAoAAAA6pCfildcdAcuc3UQuirtL User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:17186 Date: 2010-12-29T00:46:35-08:00 List-Id: On 29 Dez., 00:52, Simon Wright wrote: > kug1977 writes: > > For my programm I need a type like System.Address but with a > > definitive size of 32-bits. So I've create one > > > =A0 =A0type t_OFW_vAddress is mod t_Cell_Size; > > =A0 =A0for t_OFW_vAddress'Size use 32 ; > > =A0 =A0pragma Assert (t_OFW_vAddress'Size =3D 32); > > =A0 =A0pragma Assert (t_OFW_vAddress'Alignment =3D 4) ; > > > =A0 =A0OFW_Null_vAddress : constant t_OFW_vAddress :=3D 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 > > =A0 =A0type Chain_CI_Args is record > =A0 =A0 =A0 ... > =A0 =A0 =A0 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 > > =A0 =A0type Chain_CI_Args is record > =A0 =A0 =A0 ... > =A0 =A0 =A0 Another_Clients_Entry : Client_Entry; > =A0 =A0 =A0 Another_Clients_Arguments : System.Address; > =A0 =A0 =A0 Another_Clients_Args_Len : Integer; > =A0 =A0 =A0 ... > > so you'd write > > =A0 =A0 =A0 ... > =A0 =A0 =A0 Another_Clients_Entry =3D> Another_Clients_Entry, > =A0 =A0 =A0 Another_Clients_Arguments =3D> > =A0 =A0 =A0 =A0 =A0Another_Clients_Arguments > =A0 =A0 =A0 (Another_Clients_Arguments'First)'Address, > =A0 =A0 =A0 Another_Clients_Args_Len =3D> Another_Clients_Arguments'Lengt= h, > =A0 =A0 =A0 ... > > 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