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: 103376,17f2366fc6172420 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!c2g2000yqc.googlegroups.com!not-for-mail From: kug1977 Newsgroups: comp.lang.ada Subject: Re: Access Type Date: Fri, 24 Dec 2010 12:59:50 -0800 (PST) Organization: http://groups.google.com Message-ID: <3af2d3d1-ede9-4255-a31b-c5f66c6cee2e@c2g2000yqc.googlegroups.com> References: <8d8e1094-d021-4456-85fb-bbb2f3911334@m7g2000vbn.googlegroups.com> NNTP-Posting-Host: 78.51.81.149 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1293224390 19771 127.0.0.1 (24 Dec 2010 20:59:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 24 Dec 2010 20:59:50 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c2g2000yqc.googlegroups.com; posting-host=78.51.81.149; 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:17106 Date: 2010-12-24T12:59:50-08:00 List-Id: > > this drives me crazy, because it makes me think that I don't get this > > access concept in Ada ... hope someone can help here. > > Leave out the (1..5), and let the compiler count > how long it is. =A0You're asking for a bug here -- > you might count wrong. Good advise. It's a better job for the compile to count. Tend to be inattentively in programming. That's why I like Ada most of the time. ;-) > And you forgot "constant", both on the access type, and on the object. type t_OFW_Service_Name is array (Positive range <>) of Character; type t_OFW_Service_Name_Access is access constant t_OFW_Service_Name; open_SERVICE_NAME : aliased constant t_OFW_Service_Name :=3D "open" & Ada.Characters.Latin_1.NUL; Now, the compiler stops teasing me. Need the array of Character for a while, but will change it later to an new type of t_ofw_byte. > > 4. In my Ada-function, I use record-set like this > > > =A0 =A0 =A0type Ci_Args is record > > =A0 =A0 =A0 =A0 =A0Service =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : t_OFW_Serv= ice_Name_Access; > > =A0 =A0 =A0 end record; > > =A0 =A0 =A0 Arg =A0 : Ci_Args; > > > =A0 =A0 which I fill like this > > > =A0 =A0 Arg.Service =A0 =A0 =A0 =A0 :=3D boot_Service_Name'Access; > > You might want to use an aggregate to fill it in. > That way, the compiler will make sure you didn't > miss any components. One more thing learned today. I was looking for a construct makes sure the compiler gets me, if I forget a component. So, that's the way. > Your type says "range <>", so it's unconstrained. > Your object says (1..5), so it has an explicit constraint. > You are not allowed to take 'Access of an object with > an explicit constraint, and returning an access to > unconstrained array. =A0Some people think that's a language > design flaw. =A0They are probably right. =A0You are not the > first person to be surprised and confused by this rule. > > Anyway, the workaround is to remove the constraint, > which isn't needed anyway. =A0The compiler said > "declare without bounds", and that's what it means. > All array objects are constrained in Ada, > if not explicitly, then by the initial value. I was thinking, I've to bound the unconstrained array, but never get it, that the initial value will bound it. Pointers are an obstacle for most newbies and it takes some time to understand the principle in the first time. Now I've to learn it the Ada-way ... > Another thing you need to look out for: =A0If you are > passing this data to some other language (like C), > you need to make sure the representations match. > See pragma Import and Convention. =A0By default, GNAT > will represent an access-to-String as a fat pointer, > which won't match the C side. I will pass this to Openfirmware which is like a 32-bit C. So I use type Ci_Args is record Service : t_OFW_Service_Name_Access; ... end record; pragma Convention (C, Ci_Args); -- represent CI_Args as a C- style struct Arg : Ci_Args; I hope this will prevent the compiler from using something else than a 32-bit Address for the Service entry. Thanks Bob for helping me out. Have nice holidays. - kug1977