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!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Convert chars_ptr to Ada String Date: Mon, 10 Jul 2017 16:24:28 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <567a23f5-a7dc-4b3d-8c16-942a8551c02f@googlegroups.com> <29cb4699-2faf-4da3-8ed8-f01909054b4f@googlegroups.com> NNTP-Posting-Host: vZYCW951TbFitc4GdEwQJg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Language: en-US Xref: news.eternal-september.org comp.lang.ada:47342 Date: 2017-07-10T16:24:28+02:00 List-Id: On 10/07/2017 14:41, Mark Lorenzen wrote: > On Monday, July 10, 2017 at 11:48:29 AM UTC+2, Dmitry A. Kazakov wrote: >> On 10/07/2017 11:31, Victor Porton wrote: >> >>> Read description of Value() carefully. It stops at first NUL. >> >> if Ptr = Null_Ptr then >> return ""; >> else >> return To_Ada (Value (Ptr, Length), False); >> end if; > > I don't think that it will work as (if I understand it correctly) the > string the OP tries to convert may contain NULL characters that are > not to be interpreted as string terminators. I see, it seems that Value is broken in ARM B.3.1(35). The semantics specified is: "If Item = Null_Ptr, then Value propagates Dereference_Error. Otherwise, Value returns the shorter of two arrays, either the first Length chars pointed to by Item, or Value(Item). The lower bound of the result is 0. If Length is 0, then Value propagates Constraint_Error." which is if not useless then incomplete. There must be Trim_Nul or Ignore_Nul parameter as in To_Ada and Length=0 must be OK. > I think the problem is, that the OP is confused about the difference > between C strings and C arrays of characters and tries to use > Interfaces.C.Strings to manipulate C arrays of characters thar are not > be interpreted as C strings but as simple arrays of characters. There is no such difference. Some C functions use NUL some ignore it. The OP's request is absolutely reasonable. > Maybe Interfaces.C.Pointers is more appropriate? Yes. There seems no way other than to use Interfaces.C.Pointers and convert each character individually. I would suggest the OP to post a change request to ARG. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de