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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a6b:b58a:: with SMTP id e132-v6mr534065iof.87.1530704729264; Wed, 04 Jul 2018 04:45:29 -0700 (PDT) X-Received: by 2002:aca:c6ca:: with SMTP id w193-v6mr361869oif.1.1530704729037; Wed, 04 Jul 2018 04:45:29 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.linkpendium.com!news.linkpendium.com!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!u78-v6no1609662itb.0!news-out.google.com!z3-v6ni1749iti.0!nntp.google.com!u78-v6no1609660itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 4 Jul 2018 04:45:28 -0700 (PDT) In-Reply-To: <6294202b-73d0-4c8c-af6f-e3435b4432c3@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=220.235.48.124; posting-account=d51RWwoAAADvR-x0zYAtT9z3CRxT1eXo NNTP-Posting-Host: 220.235.48.124 References: <85743ee2-7d33-4024-a497-73a8dae0f480@googlegroups.com> <3199b658-cc7d-47be-bc4d-a8346c0d765a@googlegroups.com> <6294202b-73d0-4c8c-af6f-e3435b4432c3@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4b11d923-8412-48bc-9406-d3aaaa81e6f2@googlegroups.com> Subject: Re: Interface Ada string with C++ std::string From: Roger Injection-Date: Wed, 04 Jul 2018 11:45:29 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:53574 Date: 2018-07-04T04:45:28-07:00 List-Id: On Wednesday, July 4, 2018 at 9:23:23 PM UTC+10, Lucretia wrote: > 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. > > package CPP_Strings is > type CPP_String is private; > > function Get (S : in CPP_String) return String; -- Wrap the C->Ada stuff inside here. > private > type CPP_String is System.Address; > end CPP_Strings; 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 implement 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 thought the way ahead would be to write a C interface to C++ and then wrap the C interface to Ada as you have suggested. My original post was due to not being sure how to do it. So your advice has been a tremendous help and makes me confident that I'll get there eventually.