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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.241.40 with SMTP id wf8mr1633171pac.31.1381947181534; Wed, 16 Oct 2013 11:13:01 -0700 (PDT) X-Received: by 10.50.80.78 with SMTP id p14mr107238igx.6.1381947181455; Wed, 16 Oct 2013 11:13:01 -0700 (PDT) Path: border1.nntp.ams3.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!backlog3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder.erje.net!us.feeder.erje.net!news.linkpendium.com!news.linkpendium.com!news.snarked.org!newsfeed.news.ucla.edu!usenet.stanford.edu!z6no53905046pbz.1!news-out.google.com!9ni46435qaf.0!nntp.google.com!o2no8487919qas.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 16 Oct 2013 11:13:01 -0700 (PDT) In-Reply-To: <50cd020a-480f-4569-990b-b2861f628bc1@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=129.59.203.122; posting-account=7Oy7OQoAAABhVYFOo553Cn1-AaU-bSfl NNTP-Posting-Host: 129.59.203.122 References: <1374ac32-0fb5-4589-a9a5-7740030fd3c6@googlegroups.com> <4bb47482-ccb9-4641-a702-2b2978100ff9@googlegroups.com> <5b59543c-7c48-4427-afc6-30289f6d8895@googlegroups.com> <54aa8ad2-cd98-4f3e-bef9-494ddaefe4e9@googlegroups.com> <50cd020a-480f-4569-990b-b2861f628bc1@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Passing a String to a C/C++ Subprogram (Special Case) From: Eryndlia Mavourneen Injection-Date: Wed, 16 Oct 2013 18:13:01 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Original-Bytes: 9062 Date: 2013-10-16T11:13:01-07:00 List-Id: On Wednesday, October 16, 2013 12:54:45 PM UTC-5, Martin wrote: > On Wednesday, October 16, 2013 6:42:29 PM UTC+1, Eryndlia Mavourneen wrot= e: >=20 > > On Wednesday, October 16, 2013 12:32:36 PM UTC-5, Martin wrote: >=20 > >=20 >=20 > > > On Tuesday, October 15, 2013 10:02:17 PM UTC+1, Eryndlia Mavourneen w= rote: >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > On Tuesday, October 15, 2013 3:11:30 PM UTC-5, Adam Beneschan wrote= : >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > On Tuesday, October 15, 2013 12:54:18 PM UTC-7, Eryndlia Mavourne= en wrote: >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > I have a couple of strings that are bounded; that is, they are = essentially fixed-length strings, and I need to pass them as "in" parameter= s to a subprogram that may or may not be written in C/C++. I don't really = want to hassle with the Interfaces packages for this, since the subprogram = language is indefinite, and the strings are part of a package that many oth= ers likely will want to use, and the strings most likely will be used as st= andard Ada fixed-length strings. >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > Q: Is there any reason that I cannot just declare each of them = in this way, assuming the subprogram is written in C/C++: >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > . . . >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > A_String : String (1 .. 30); >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > pragma Convention (C, A_String); >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > . . . >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > procedure C_Prog (C_String : in String); >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > pragma Import (Entity =3D> C_Prog, ...); >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > begin >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > C_Prog (C_String =3D> A_String); >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > . . . >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > > and have it work properly? >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > B.3(70) says, "An Ada parameter of an array type with component t= ype T, of any mode, is passed as a t* argument to a C function, where t is = the C type corresponding to the Ada type T." Since a String is defined as = an array of Character in Ada, this should cause a "char*" argument to be pa= ssed. However, this is in a section marked "Implementation Advice", so the= re's a possibility that a particular Ada compiler may not conform. You'll = want to check the Ada compiler manual and/or try it yourself and see what c= ode it generates. Note that this means the 'First and 'Last of the string = parameter won't be passed to the C routine. But it looks like you know tha= t already.=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > > -- Adam >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > Yes, Adam. Thank you. Of course, Annex B is optional anyway. lol >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > I guess you choose your poison. >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > > -- Eryndlia Mavourneen (KK1T) >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > Annex B is part of the 'core language' - it isn't optional. Annex A a= nd J are also 'core'. The 'Special Needs Annex' sections are the 'optional'= parts of the language. See 1.1.2 and 1.1.3. >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > >=20 >=20 > >=20 >=20 > > > -- Martin >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > > In the Ada95 LRM (I have to use Ada95.), in the introduction to Annex B= (B 2/3) it states: "Support for interfacing to any foreign language is op= tional." >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > > -- Eryndlia Mavourneen (KK1T) >=20 >=20 >=20 > That looks like Ada2012 RM rather than Ada95 (or Ada2005) [http://www.ada= -auth.org/standards/12rm/html/RM-B.html]. >=20 >=20 >=20 > But I do like the Ada2012 wording...it seems clearer - either the compile= r has to indicate the lack of support; or exception has to be raised. If ne= ither of those occur then your code should work as expected. >=20 >=20 >=20 > -- Martin Yes. You're right. My Mistake. -- Eryndlia Mavourneen (KK1T)