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 2002:a6b:df0d:: with SMTP id w13-v6mr585586iog.32.1530705155064; Wed, 04 Jul 2018 04:52:35 -0700 (PDT) X-Received: by 2002:aca:f495:: with SMTP id s143-v6mr365064oih.7.1530705154758; Wed, 04 Jul 2018 04:52:34 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.unit0.net!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!85.12.16.70.MISMATCH!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.am4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!u78-v6no1614662itb.0!news-out.google.com!l67-v6ni1550itl.0!nntp.google.com!d7-v6no1615638itj.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 4 Jul 2018 04:52:34 -0700 (PDT) In-Reply-To: <4b11d923-8412-48bc-9406-d3aaaa81e6f2@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2a02:c7d:3c35:b000:325a:3aff:fe0f:37a5; posting-account=L2-UcQkAAAAfd_BqbeNHs3XeM0jTXloS NNTP-Posting-Host: 2a02:c7d:3c35:b000:325a:3aff:fe0f:37a5 References: <85743ee2-7d33-4024-a497-73a8dae0f480@googlegroups.com> <3199b658-cc7d-47be-bc4d-a8346c0d765a@googlegroups.com> <6294202b-73d0-4c8c-af6f-e3435b4432c3@googlegroups.com> <4b11d923-8412-48bc-9406-d3aaaa81e6f2@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Interface Ada string with C++ std::string From: Lucretia Injection-Date: Wed, 04 Jul 2018 11:52:35 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 3383 X-Received-Body-CRC: 4131279563 Xref: reader02.eternal-september.org comp.lang.ada:53575 Date: 2018-07-04T04:52:34-07:00 List-Id: On Wednesday, 4 July 2018 12:45:30 UTC+1, Roger wrote: > On Wednesday, July 4, 2018 at 9:23:23 PM UTC+10, Lucretia wrote: >=20 > > All you probably need is a C function which returns the string c_str() = to Ada which Ada can then use, wrap that in Ada. Just define a private type= for the string class which is an address and pass that to the C function. > >=20 > > package CPP_Strings is > > type CPP_String is private; > >=20 > > function Get (S : in CPP_String) return String; -- Wrap the C->Ada s= tuff inside here. > > private > > type CPP_String is System.Address; > > end CPP_Strings; >=20 > Thanks, > I was playing around today modifying your test_binding code then managed = to accidentally delete everything I'd done! > I think I'll have another go at it as it is an educational experience. > Once I've done that, I'll be in a better position to understand and imple= ment what you've just suggested. > Everything is pretty much in line with my thinking. My main problem is my= minimal experience with C++ so your helping hand is very welcome. > Once I found it impossible to directly interface std::string to Ada, I th= ought the way ahead would be to write a C interface to C++ and then wrap th= e C interface to Ada as you have suggested. > My original post was due to not being sure how to do it. So your advice h= as been a tremendous help and makes me confident that I'll get there eventu= ally. The test_binding is the extreme way to do it. The simpler, kind of, and preferred way would be to work out what you need = from the string class. Pass around the C++ pointer inside Ada. Then have C = functions which are imported to Ada which handle the messy C/C++ stuff, the= n wrap those in Ada handling the Messy Ada/C stuff there.