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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,6a1865ea6d613695 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Received: by 10.68.35.131 with SMTP id h3mr26516329pbj.1.1322497417513; Mon, 28 Nov 2011 08:23:37 -0800 (PST) Path: lh20ni31131pbb.0!nntp.google.com!news1.google.com!postnews.google.com!f29g2000yqa.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Interfaces.C.String.Update Date: Mon, 28 Nov 2011 08:22:08 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <83380fe1-c4c4-4b32-8f2e-f9cc4a862644@n35g2000yqf.googlegroups.com> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 X-Trace: posting.google.com 1322497328 13880 127.0.0.1 (28 Nov 2011 16:22:08 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 28 Nov 2011 16:22:08 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f29g2000yqa.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-Via: ICAP/1.0 192.168.152.4 X-Google-Web-Client: true X-Google-Header-Order: HUALESRCVNK X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.8) Gecko/20100728 Firefox/3.6.8 (.NET CLR 3.5.30729),gzip(gfe) Xref: news1.google.com comp.lang.ada:19215 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-11-28T08:22:08-08:00 List-Id: 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 =A0set 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 =3D> 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 :=3D 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.