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,deffccd74319c23d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news2.google.com!proxad.net!newsfeed.icl.net!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Sending Variable Length Messages with GNAT.Sockets Date: Tue, 10 May 2005 21:34:40 +0100 Organization: Pushface Message-ID: References: <1115633512.107824.259680@g14g2000cwa.googlegroups.com> <427f3dfa$0$28058$ba620e4c@news.skynet.be> <1115637556.074009.113830@o13g2000cwo.googlegroups.com> <1115650283.330746.109740@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1115757282 4543 62.49.19.209 (10 May 2005 20:34:42 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Tue, 10 May 2005 20:34:42 +0000 (UTC) Cancel-Lock: sha1:hTXn9pP4is1DQTtSRwjwtLYkjdU= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Xref: g2news1.google.com comp.lang.ada:10987 Date: 2005-05-10T21:34:40+01:00 List-Id: Simon Wright writes: > declare > Readable : my_array_type (1 .. number_of_array_elements); > begin > my_array_type'Read (str, Readable); I forgot to say, you need to be careful about the components of records if you're going to let the compiler use the default 'Read/'Write. If the C side says struct rec { char flag; int count; }; there will typically be 3 bytes of padding between flag & count, for 8 bytes on the wire. If the Ada side says type Rec is record Flag : Interfaces.Unsigned_8; Count : Interfaces.Integer_32; end record; pragma Convention (C, Rec); the 'Write will output *5* bytes; but an unchecked conversion to Stream_Element_Array (1 .. 8) will succeed & do The Right Thing (endianness permitting).