From: Martin <martin@thedowies.com>
Subject: Re: Passing a String to a C/C++ Subprogram (Special Case)
Date: Wed, 16 Oct 2013 10:32:36 -0700 (PDT)
Date: 2013-10-16T10:32:36-07:00 [thread overview]
Message-ID: <5b59543c-7c48-4427-afc6-30289f6d8895@googlegroups.com> (raw)
In-Reply-To: <4bb47482-ccb9-4641-a702-2b2978100ff9@googlegroups.com>
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:
>
> > On Tuesday, October 15, 2013 12:54:18 PM UTC-7, Eryndlia Mavourneen wrote:
>
> >
>
> > > 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" parameters 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 others likely will want to use, and the strings most likely will be used as standard Ada fixed-length strings.
>
> >
>
> > > Q: Is there any reason that I cannot just declare each of them in this way, assuming the subprogram is written in C/C++:
>
> >
>
> > > . . .
>
> > > A_String : String (1 .. 30);
>
> > > pragma Convention (C, A_String);
>
> > > . . .
>
> > > procedure C_Prog (C_String : in String);
>
> > > pragma Import (Entity => C_Prog, ...);
>
> > > begin
>
> > > C_Prog (C_String => A_String);
>
> > > . . .
>
> >
>
> > > and have it work properly?
>
> >
>
> >
>
> >
>
> > 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 array 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 to 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 parameter won't be passed to the C routine. But it looks like you know that already.
>
> >
>
> >
>
> >
>
> > -- Adam
>
>
>
> Yes, Adam. Thank you. Of course, Annex B is optional anyway. lol
>
> I guess you choose your poison.
>
>
>
> -- Eryndlia Mavourneen (KK1T)
Annex B is part of the 'core language' - it isn't optional. Annex A and J are also 'core'. The 'Special Needs Annex' sections are the 'optional' parts of the language. See 1.1.2 and 1.1.3.
-- Martin
next prev parent reply other threads:[~2013-10-16 17:32 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-15 19:54 Passing a String to a C/C++ Subprogram (Special Case) Eryndlia Mavourneen
2013-10-15 20:11 ` Adam Beneschan
2013-10-15 21:02 ` Eryndlia Mavourneen
2013-10-16 7:17 ` Dmitry A. Kazakov
2013-10-16 15:14 ` Jeffrey Carter
2013-10-16 17:32 ` Martin [this message]
2013-10-16 17:42 ` Eryndlia Mavourneen
2013-10-16 17:54 ` Martin
2013-10-16 18:13 ` Eryndlia Mavourneen
2013-10-16 19:40 ` Simon Wright
2013-10-16 20:02 ` Eryndlia Mavourneen
2013-10-19 2:11 ` Randy Brukardt
2013-10-16 19:11 ` Adam Beneschan
2013-10-16 21:31 ` Martin
2013-10-16 21:41 ` Adam Beneschan
2013-10-16 23:15 ` Martin
2013-10-15 20:59 ` Jeffrey Carter
2013-10-15 21:13 ` Eryndlia Mavourneen
2013-10-15 22:19 ` Shark8
2013-10-16 0:00 ` Jeffrey Carter
2013-10-17 9:55 ` Georg Bauhaus
2013-10-16 20:17 ` sbelmont700
2013-10-16 20:48 ` Adam Beneschan
2013-10-17 13:05 ` Eryndlia Mavourneen
2013-10-17 13:58 ` sbelmont700
2013-10-17 16:28 ` Eryndlia Mavourneen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox