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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,dbaf05888e191cb6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-15 12:48:54 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc51.ops.asp.att.net.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Access to array slices? References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 12.234.13.56 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc51.ops.asp.att.net 1042663734 12.234.13.56 (Wed, 15 Jan 2003 20:48:54 GMT) NNTP-Posting-Date: Wed, 15 Jan 2003 20:48:54 GMT Organization: AT&T Broadband Date: Wed, 15 Jan 2003 20:48:54 GMT Xref: archiver1.google.com comp.lang.ada:33050 Date: 2003-01-15T20:48:54+00:00 List-Id: > I am curious as to whether you deliberately avoided > Interfaces.C.Strings (ICS) or the not mentioning it was > an oversight ? Perhaps I misunderstood the original question. I was responding to: > What I was able to figure out so far is that a fat pointer is two and > Is it common for C interfacing code to copy data in and out like > crazy? Without the ability to obtain an Access to array slice this > must be the case, right? It seemed you wanted to avoid copying, while still being able to talk about certain substrings of a single large Interfaces.C.Char_Array. You can't use an "access all Interfaces.C.Char_Array" because that's unconstrained and the access value would need a place to store the length. But if the original data from the socket (or wherever) is a big Interfaces.C.Char_Array containing a series of [name_length, value_length, name, value] sequences, then you can have a scan routine that finds the name_length, value_length, and starting index for "name" of a single sequence. Big : Interfaces.C.Char_Array(...); Name_Length, Value_Length, Name_Start : Interfaces.C.Size_T; Given those, Big(Name_Start .. Name_Start+Name_Length-1) is an Interfaces.C.Char_Array containing the name part, and Big(Name_Start+Name_Length .. Name_Start+Name_Length+Value_Length-1) is an Interfaces.C.Char_Array consisting of the "value" part, and the next name_length count is to be found starting at Big(Name_Start+Name_Length+Value_Length .. ) Here's a dummy (but working) program to show the idea: with Interfaces.C; with Ada.Text_Io; procedure Testcs is Big : Interfaces.C.Char_Array := Interfaces.C.To_C("now is the time"); First, Last : Interfaces.C.Size_T; Word_Number: Positive := 1; procedure Find_Next_Word is -- somehow find values for First and Last begin case Word_Number is when 1 => First := 0; Last := 2; when 2 => First := 4; Last := 5; when 3 => First := 7; Last := 9; when 4 => First := 11;Last := 14; when others => First := 0; Last := 0; end case; Word_Number := Word_Number + 1; end Find_Next_Word; procedure Show(C_String : in Interfaces.C.Char_Array) is begin Ada.Text_Io.Put_Line(Interfaces.C.To_Ada(C_String, Trim_Nul => False)); end Show; begin for I in 1 .. 4 loop Find_Next_Word; Show(Big(First .. Last)); end loop; end Testcs; procedure Show has, in effect, been handed a pointer to a dynamic length substring of Big. No copying has been done.