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.42.112.138 with SMTP id y10mr4220475icp.28.1381870938798; Tue, 15 Oct 2013 14:02:18 -0700 (PDT) X-Received: by 10.50.85.50 with SMTP id e18mr541544igz.9.1381870938736; Tue, 15 Oct 2013 14:02:18 -0700 (PDT) Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!o2no6977138qas.0!news-out.google.com!9ni40949qaf.0!nntp.google.com!o2no6977129qas.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 15 Oct 2013 14:02:17 -0700 (PDT) In-Reply-To: <1374ac32-0fb5-4589-a9a5-7740030fd3c6@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=129.59.203.120; posting-account=7Oy7OQoAAABhVYFOo553Cn1-AaU-bSfl NNTP-Posting-Host: 129.59.203.120 References: <1374ac32-0fb5-4589-a9a5-7740030fd3c6@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4bb47482-ccb9-4641-a702-2b2978100ff9@googlegroups.com> Subject: Re: Passing a String to a C/C++ Subprogram (Special Case) From: Eryndlia Mavourneen Injection-Date: Tue, 15 Oct 2013 21:02:18 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Original-Bytes: 3346 Xref: number.nntp.dca.giganews.com comp.lang.ada:183625 Date: 2013-10-15T14:02:17-07:00 List-Id: On Tuesday, October 15, 2013 3:11:30 PM UTC-5, Adam Beneschan wrote: > On Tuesday, October 15, 2013 12:54:18 PM UTC-7, Eryndlia Mavourneen wrote= : >=20 > > I have a couple of strings that are bounded; that is, they are essentia= lly fixed-length strings, and I need to pass them as "in" parameters to a s= ubprogram 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 others like= ly will want to use, and the strings most likely will be used as standard A= da fixed-length strings. >=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 > > . . . > > A_String : String (1 .. 30); > > pragma Convention (C, A_String); > > . . . > > procedure C_Prog (C_String : in String); > > pragma Import (Entity =3D> C_Prog, ...); > > begin > > C_Prog (C_String =3D> A_String); > > . . . >=20 > > and have it work properly? >=20 >=20 >=20 > B.3(70) says, "An Ada parameter of an array type with component type T, o= f any mode, is passed as a t* argument to a C function, where t is the C ty= pe 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 passed. H= owever, this is in a section marked "Implementation Advice", so there's a p= ossibility 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 code it g= enerates. Note that this means the 'First and 'Last of the string paramete= r won't be passed to the C routine. But it looks like you know that alread= y.=20 >=20 >=20 >=20 > -- Adam Yes, Adam. Thank you. Of course, Annex B is optional anyway. lol I guess you choose your poison. -- Eryndlia Mavourneen (KK1T)