comp.lang.ada
 help / color / mirror / Atom feed
From: Eryndlia Mavourneen <eryndlia@gmail.com>
Subject: Passing a String to a C/C++ Subprogram (Special Case)
Date: Tue, 15 Oct 2013 12:54:18 -0700 (PDT)
Date: 2013-10-15T12:54:18-07:00	[thread overview]
Message-ID: <e87e8a92-9822-4764-a4a6-1fbc6715ef52@googlegroups.com> (raw)

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?

This method, of course, leaves it up to the client developer to insert any necessary nul characters to terminate the string, if is is smaller than the declared bound.

-- Eryndlia Mavourneen (KK1T)

             reply	other threads:[~2013-10-15 19:54 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-15 19:54 Eryndlia Mavourneen [this message]
2013-10-15 20:11 ` Passing a String to a C/C++ Subprogram (Special Case) 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
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