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,43ad9ab56ebde91c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.75.170 with SMTP id d10mr4909217pbw.6.1323954079088; Thu, 15 Dec 2011 05:01:19 -0800 (PST) Path: lh20ni25309pbb.0!nntp.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Does Ada support endiannes? Date: Thu, 15 Dec 2011 13:01:17 +0000 Organization: A noiseless patient Spider Message-ID: References: <23835087-313f-427c-b37e-4ff1bdef9d57@r6g2000yqr.googlegroups.com> <108d5437-ae36-4e79-ad4e-aab3b903d0f4@gl2g2000vbb.googlegroups.com> <2f9744b6-4a45-4dd1-9621-c6f5d10166cb@r6g2000yqr.googlegroups.com> <0a7b55fd-1ecf-4a40-979c-12ce44071be9@p9g2000vbb.googlegroups.com> <6779f55b-e110-4673-b70b-cbd7c58f5d78@j10g2000vbe.googlegroups.com> <71bc4e7f-7c23-4180-9a8d-5c880a16d0c2@p16g2000yqd.googlegroups.com> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="19132"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183ukTLOHR4kopWuTRq+0slPsKV4bCjmls=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:Z198qG3hWDSZhXj+DLbFqUVXUNc= sha1:k9tuAnnxgc+H51KDVwqOEnGUsRE= Content-Type: text/plain; charset=us-ascii Date: 2011-12-15T13:01:17+00:00 List-Id: Gerd writes: > The problem space requires integers (signed), so using unsigned is not > the right option. > > Could you please explain: What do you think how the data send from 68k > to x86 will be converted from one data layout to the other? Will it > happen "magically" on the wire? I think, conversion must be done > explicit either on one side or on the other side, and this requires > some code. > > Currently I use the htonl ntohl functions for it, which (as stated > above) is not a good choice as it limits the allowed values to > unsigned. Some code I wrote -- not quite the same problem -- which handles 8-byte signed quantities and conversion to/from wire format, and works just fine on i386, x86_64, powerpc, is type SNTP_Timestamp is delta 2.0 ** (-32) range -2.0 ** 31 .. 2.0 ** 31; for SNTP_Timestamp'Size use 64; subtype Timestamp_Slice is Ada.Streams.Stream_Element_Array (1 .. 8); function To_Timestamp_Slice (T : SNTP_Timestamp) return Timestamp_Slice is function Convert is new Ada.Unchecked_Conversion (SNTP_Timestamp, Timestamp_Slice); Tmp : constant Timestamp_Slice := Convert (T); begin if Big_Endian then return Tmp; else return (1 => Tmp (8), 2 => Tmp (7), 3 => Tmp (6), 4 => Tmp (5), 5 => Tmp (4), 6 => Tmp (3), 7 => Tmp (2), 8 => Tmp (1)); end if; end To_Timestamp_Slice; function To_SNTP_Timestamp (T : Timestamp_Slice) return SNTP_Timestamp is function Convert is new Ada.Unchecked_Conversion (Timestamp_Slice, SNTP_Timestamp); begin if Big_Endian then return Convert (T); else return Convert ((1 => T (8), 2 => T (7), 3 => T (6), 4 => T (5), 5 => T (4), 6 => T (3), 7 => T (2), 8 => T (1))); end if; end To_SNTP_Timestamp; No real possibility of validation of this data type at the conversion level, of course. I think the chance of using wierd machines where this doesn't work is pretty low. And don't forget you can come a cropper because of compiler changes: previous to Ada 2005, GNAT's representation of Ada.Calendar.Time used the Unix epoch, so a conversion based on that seemed a pretty safe bet.