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: 103376,6a1865ea6d613695 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.205.127.148 with SMTP id ha20mr7048504bkc.6.1322501888233; Mon, 28 Nov 2011 09:38:08 -0800 (PST) Path: dq5ni64736bkb.0!nntp.google.com!news2.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 09:37: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 1322501828 27819 127.0.0.1 (28 Nov 2011 17:37:08 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 28 Nov 2011 17:37: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.2 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: news2.google.com comp.lang.ada:14705 Content-Type: text/plain; charset=ISO-8859-1 Date: 2011-11-28T09:37:08-08:00 List-Id: awdorrin wrote on comp.lang.ada: > Thanks for the confirmation and the suggestions. > > One followup question about Update and the use of Check=>True... > > If I'm understanding things properly, given the following scenario: > > Character array defined in C, initialized with a memset of nulls. > > Passing a char* to Ada, using the Chars_Ptr - Any attempt to use > Update with Check=>True will raise an Update_Error, because Ada will > see the string pointed to as zero length, right? Right. > So this requires us to disable the check and do some checking on both > sides to make sure that we don't blow the char buffers. Right. > I think, updating these functions to pass in the buffer length (or > 'cheating' by initializing the char arrays with spaces instead of > nulls) would be safer, and allow me to take advantage of the > Check=>True functionality. In this case I would think it is easier to forget about C's notion of a string (null-terminated, no length) and use Ada's notion on both sides (length known at run time). If you control the C side of your system, you can easily make it allocate exactly the length needed and pass the length explicitly. Then on the Ada side you do not need Interfaces.C.Strings anymore, just copy one char_array to another. -- Ludovic Brenta. Our gut-feeling is that the stakeholders transition a progressive trend across the board.