comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Interfaces.C.String.Update
Date: Mon, 28 Nov 2011 08:09:53 -0800 (PST)
Date: 2011-11-28T08:09:53-08:00	[thread overview]
Message-ID: <4f5bf5fb-e4a6-4048-be85-29948585e2f9@z12g2000yqm.googlegroups.com> (raw)
In-Reply-To: 83380fe1-c4c4-4b32-8f2e-f9cc4a862644@n35g2000yqf.googlegroups.com

On Nov 28, 7:55 am, awdorrin <awdor...@gmail.com> wrote:
> What is the suggested method to null terminate an Ada string being
> passed back to C via Interfaces.C.Strings.Update() ?
>
> I've been looking at the code for i-cstrin.adb, and it seems that by
> default that the procedure, when passing in an Ada String, uses To_C
> with Append_Null  set to False.

Right, that's actually in the RM.  B.3.1(49-50):

[49] procedure Update (Item   : in chars_ptr;
                       Offset : in size_t;
                       Str    : in String;
                       Check  : in Boolean := True);

[50] Equivalent to Update(Item, Offset, To_C(Str, Append_Nul =>
False), Check).

Since that's the language used in the RM, it seems most appropriate to
me that if you want to do the same kind of Update but *with* a null
character appended, you'd use the same code shown in the RM but with
Append_Nul => True.  It probably doesn't matter except as a matter of
style, but that's what I'd do (unless execution speed is *very*
critical, in which case a function call such as To_C that returns an
unconstrained array could involve too much overhead.  I doubt that's
true in your case).

                  -- Adam



  reply	other threads:[~2011-11-28 16:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-28 15:55 Interfaces.C.String.Update awdorrin
2011-11-28 16:09 ` Adam Beneschan [this message]
2011-11-28 16:22 ` Interfaces.C.String.Update Ludovic Brenta
2011-11-28 16:35   ` Interfaces.C.String.Update awdorrin
2011-11-28 17:37     ` Interfaces.C.String.Update Ludovic Brenta
replies disabled

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