From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Interfaces.C.String.Update
Date: Mon, 28 Nov 2011 08:22:08 -0800 (PST)
Date: 2011-11-28T08:22:08-08:00 [thread overview]
Message-ID: <b6bdc1a3-c20c-4cac-9791-07a671861f85@f29g2000yqa.googlegroups.com> (raw)
In-Reply-To: 83380fe1-c4c4-4b32-8f2e-f9cc4a862644@n35g2000yqf.googlegroups.com
awdorrin wrote on comp.lang.ada:
> 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.
>
> I was trying to determine if I should manually place the null
> character, or instead call Update like:
>
> Update( cPtr, 0, To_C( AStr, Append_Nul => True), False);
>
> I haven't been able to find any discussions on this, so I'm just not
> sure what the 'best' approach for this would be.
I think you are correct, perhaps a more terse idiom would be:
Update( cPtr, 0, AStr & ASCII.NUL, False);
This is because, if Check is True,
procedure Update (Item : in chars_ptr;
Offset : in size_t;
Chars : in char_array;
Check : Boolean := True);
assumes that Item is null-terminated on input in order to call
Strlen (Item), but does not require Chars to be null-terminated
because
Chars is a char_array with known bounds. If Item is not null-
terminated
before you call Update, you're in for C-style trouble :)
If Check is False, all bets are off, so you'd better null-terminate
Item manually.
--
Ludovic Brenta.
The synchronized executive talents result in the functional successful
execution.
next prev parent reply other threads:[~2011-11-28 16:23 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 ` Interfaces.C.String.Update Adam Beneschan
2011-11-28 16:22 ` Ludovic Brenta [this message]
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