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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!talisker.lacave.net!lacave.net!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 17 Oct 2013 11:55:17 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Passing a String to a C/C++ Subprogram (Special Case) References: <9ee842b6-b053-4f4e-94df-66459ec1fb7c@googlegroups.com> In-Reply-To: <9ee842b6-b053-4f4e-94df-66459ec1fb7c@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <525fb3f5$0$6562$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 17 Oct 2013 11:55:01 CEST NNTP-Posting-Host: 36b8f025.newsspool4.arcor-online.net X-Trace: DXC=Y:g3o1hZ^CF0YVY]kmLTlD4IUK_dCnc\616M64>JLh>_cHTX3jM0K7Mkh?iN3J X-Complaints-To: usenet-abuse@arcor.de Xref: news.eternal-september.org comp.lang.ada:17451 Date: 2013-10-17T11:55:01+02:00 List-Id: On 15.10.13 23:13, Eryndlia Mavourneen wrote: > Thanks, Jeff. This could be a good way to manage things. Unfortunately, I can not guarantee that I can perform a trim operation or that the last character is indeed not being used (for the placement of a nul). There is, in addition, a logical bridge between the languages in addition to the technical one: C programmers who know the "strn..." functions of C's standard C library will not be surprised to see a subprogram profile involving a string that has both a char* and a size_t. (In fact, this way of handling string data is sometimes recommended.) Then, type My_Size_T is mod 2**Positive'Size; procedure C_Prog (C_String : in String; C_Size_T : in My_Size_T); where My_Size_T reflects String's index type. It might be a slightly more reliable approximation to what you'd write with Interfaces.*. and Conventions applied to the types, especially in corner cases when the string is empty, or if all components allocated are used so that there is no room for storing a terminating '\0' in C. There can be concerns about size_t being too different from My_Size_T just like char'Size and Character'Size might differ. (E.g. Janus/Ada reportedly has Positive'Size = 16 while the C compiler's size_t may require more than 16 bits.) Sizes can be checked at compile time.