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 06:44:20 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn14feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc04.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: <5ad0dd8a.0301141717.2f1a9685@posting.google.com> Subject: Re: Access to array slices? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: <7teV9.60727$No.7357@sccrnsc04> NNTP-Posting-Host: 12.211.13.75 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc04 1042641859 12.211.13.75 (Wed, 15 Jan 2003 14:44:19 GMT) NNTP-Posting-Date: Wed, 15 Jan 2003 14:44:19 GMT Organization: AT&T Broadband Date: Wed, 15 Jan 2003 14:44:19 GMT Xref: archiver1.google.com comp.lang.ada:33034 Date: 2003-01-15T14:44:19+00:00 List-Id: "Wojtek Narczynski" wrote in message news:5ad0dd8a.0301141717.2f1a9685@posting.google.com... > Hello, > > I am trying to develop a library that reads C structures from socket > and interpret them. > > At some point I have a structure (stream?) on stack that contains > multiple strings inside. It's something like [name_length, > value_length, name, value]* mean an unknown number of such name-value > pairs. I am able to access it as String using the 'Address clause, but > now I either have to copy the strings out, or obtain (deadly unsafe, > not portable, nobody knows why) Access'es to slices of this array. > The first thing I would do is forget that the data comes from C structures, since from what you have described that is unimportant. The code to read one of these structures would look something like: Get( socket, name_length ); Get( socket, value_length ); declare name : string( 1 .. name_length ); value : string( 1 .. value_length ); begin Get( socket, name ); Get( socket, value ); Do_Something_With_Data( name, value ); end; You may have to tweak this depending on whether the strings in your data stream have null terminators and whether the the lengths include the terminators. This assume you have overloaded functions for reading lengths and strings from a socket, which are easy to create if you don't already have them. You could also use Ada streams. When I look at an interface specification for messages sent using sockets, I hate to see the specification described in terms of C structures. I much prefer a language independent data specification. Even if communication is between two C programs, the compiler(s) may do different things depending on architecture, vendor or compiler switches. In fact when dealing with a network I make it a point to put things into network byte order. I hope this helps, Steve (The Duck)