comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Convert chars_ptr to Ada String
Date: Mon, 10 Jul 2017 16:24:28 +0200
Date: 2017-07-10T16:24:28+02:00	[thread overview]
Message-ID: <ok02mr$1115$1@gioia.aioe.org> (raw)
In-Reply-To: 29cb4699-2faf-4da3-8ed8-f01909054b4f@googlegroups.com

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

  reply	other threads:[~2017-07-10 14:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-07 21:03 Convert chars_ptr to Ada String Victor Porton
2017-07-07 22:23 ` Anh Vo
2017-07-07 22:48   ` Victor Porton
2017-07-07 23:14     ` Anh Vo
2017-07-09  6:49       ` Victor Porton
2017-07-10  4:58         ` Anh Vo
2017-07-10  9:31           ` Victor Porton
2017-07-10  9:48             ` Dmitry A. Kazakov
2017-07-10 12:41               ` Mark Lorenzen
2017-07-10 14:24                 ` Dmitry A. Kazakov [this message]
2017-07-10 21:21                   ` Victor Porton
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox