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-14 19:13:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn11feed!worldnet.att.net!204.127.198.204!attbi_feed4!attbi_feed3!attbi.com!sccrnsc03.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Access to array slices? References: <5ad0dd8a.0301141717.2f1a9685@posting.google.com> X-Newsreader: Tom's custom newsreader Message-ID: <1l4V9.55183$Dn.10134@sccrnsc03> NNTP-Posting-Host: 12.234.13.56 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc03 1042600381 12.234.13.56 (Wed, 15 Jan 2003 03:13:01 GMT) NNTP-Posting-Date: Wed, 15 Jan 2003 03:13:01 GMT Organization: AT&T Broadband Date: Wed, 15 Jan 2003 03:13:02 GMT Xref: archiver1.google.com comp.lang.ada:33025 Date: 2003-01-15T03:13:02+00:00 List-Id: > What I was able to figure out so far is that a fat pointer is two An Ada Unconstrained string has two pieces of information - the characters and the length. Your C strings are missing the second. So you can either copy them (up to nul) and put them into correct size Ada Strings, or you can forget about String lengths and handle them as C would. type C_Char_Ptrs is access all Interfaces.C.Char; type C_String_Ptrs is access all Interfaces.C.Char_Array(Interfaces.C.Size_T); -- a pointer to a fixed size (albeit huge) char_array function Convert is new Ada.Unchecked_Conversion (Source=>C_Char_Ptrs, Target=>C_String_Ptrs); Big_Collection_Of_C_Strings : Interfaces.C.Char_Array(...) Chopped : array(1 .. n) of C_String_Ptrs; Count : Natural := 0; si : Interfaces.C.Size_T := Big_Collection_Of_C_Strings'first; begin loop Count := Count+1; Chopped(Count) := Convert(Big_Collection_Of_C_String(si'unchecked_access)); -- now scan si up to the start of the next logical string -- exit if no more end loop; Of course Ada will think that Chopped(i).all is an extremely long string, so it's up to you to keep your indexes in range. If you call your processing routines with slices process(Chopped(i)(0 .. size(i))); then the processing routines will believe there are index range limits. If you can process everything sequentially, you can skip most of the above and just loop first := determine first index of this part last := determine last index of this part process(Big_Collection_Of_C_Strings(first .. last)); end loop;