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 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.58.1.1 with SMTP id 1mr1314714vei.23.1381944756897; Wed, 16 Oct 2013 10:32:36 -0700 (PDT) X-Received: by 10.49.76.38 with SMTP id h6mr131411qew.9.1381944756846; Wed, 16 Oct 2013 10:32:36 -0700 (PDT) Path: border1.nntp.ams3.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder.erje.net!us.feeder.erje.net!news.ripco.com!news.glorb.com!i2no15974560qav.0!news-out.google.com!9ni45434qaf.0!nntp.google.com!i2no15974556qav.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 16 Oct 2013 10:32:36 -0700 (PDT) In-Reply-To: <4bb47482-ccb9-4641-a702-2b2978100ff9@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=82.43.197.131; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G NNTP-Posting-Host: 82.43.197.131 References: <1374ac32-0fb5-4589-a9a5-7740030fd3c6@googlegroups.com> <4bb47482-ccb9-4641-a702-2b2978100ff9@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <5b59543c-7c48-4427-afc6-30289f6d8895@googlegroups.com> Subject: Re: Passing a String to a C/C++ Subprogram (Special Case) From: Martin Injection-Date: Wed, 16 Oct 2013 17:32:36 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Original-Bytes: 3986 Date: 2013-10-16T10:32:36-07:00 List-Id: On Tuesday, October 15, 2013 10:02:17 PM UTC+1, Eryndlia Mavourneen wrote: > On Tuesday, October 15, 2013 3:11:30 PM UTC-5, Adam Beneschan wrote: >=20 > > On Tuesday, October 15, 2013 12:54:18 PM UTC-7, Eryndlia Mavourneen wro= te: >=20 > >=20 >=20 > > > I have a couple of strings that are bounded; that is, they are essent= ially fixed-length strings, and I need to pass them as "in" parameters to a= subprogram that may or may not be written in C/C++. I don't really want t= o hassle with the Interfaces packages for this, since the subprogram langua= ge is indefinite, and the strings are part of a package that many others li= kely will want to use, and the strings most likely will be used as standard= Ada fixed-length strings. >=20 > >=20 >=20 > > > Q: Is there any reason that I cannot just declare each of them in thi= s way, assuming the subprogram is written in C/C++: >=20 > >=20 >=20 > > > . . . >=20 > > > A_String : String (1 .. 30); >=20 > > > pragma Convention (C, A_String); >=20 > > > . . . >=20 > > > procedure C_Prog (C_String : in String); >=20 > > > pragma Import (Entity =3D> C_Prog, ...); >=20 > > > begin >=20 > > > C_Prog (C_String =3D> A_String); >=20 > > > . . . >=20 > >=20 >=20 > > > and have it work properly? >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > > B.3(70) says, "An Ada parameter of an array type with component type 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 arr= ay of Character in Ada, this should cause a "char*" argument to be passed. = However, this is in a section marked "Implementation Advice", so there's a= possibility that a particular Ada compiler may not conform. You'll want t= o check the Ada compiler manual and/or try it yourself and see what code it= generates. Note that this means the 'First and 'Last of the string parame= ter won't be passed to the C routine. But it looks like you know that alre= ady.=20 >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > > -- Adam >=20 >=20 >=20 > Yes, Adam. Thank you. Of course, Annex B is optional anyway. lol >=20 > I guess you choose your poison. >=20 >=20 >=20 > -- Eryndlia Mavourneen (KK1T) Annex B is part of the 'core language' - it isn't optional. Annex A and J a= re also 'core'. The 'Special Needs Annex' sections are the 'optional' parts= of the language. See 1.1.2 and 1.1.3. -- Martin