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,4e9860765413318c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-24 01:04:03 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!IRIS.global-one.nl!news1.global-ip.net!news3.global-ip.net!not-for-mail Message-ID: <3B860BD6.7A1A8EA3@eraseme.systems.saab.se> From: Peter Dulimov X-Mailer: Mozilla 4.61 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Hi byte and Lo Byte Question References: <9m0gn6$b6j$1@zeus.orl.lmco.com> <3B843C0C.9A3282B@raytheon.com> <9m34r7$6ka$1@nh.pace.co.uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 24 Aug 2001 10:09:59 +0200 NNTP-Posting-Host: 139.58.232.1 X-Trace: news3.global-ip.net 998640219 139.58.232.1 (Fri, 24 Aug 2001 10:03:39 MET DST) NNTP-Posting-Date: Fri, 24 Aug 2001 10:03:39 MET DST Xref: archiver1.google.com comp.lang.ada:12374 Date: 2001-08-24T10:09:59+02:00 List-Id: This is a really good idea. I have spent a lot of time doing this manually, and inefficiently (in terms of produced code, as well as the speed at which I produce it), in Ada83 (so not even modular types available.) Also, the original poster's problem --- switching byte order --- becomes easy. Cheers, Peter Dulimov. Marin David Condic wrote: [snip - stuff deleted] > Here's a proposition worth discussing: > > In a lot of embedded apps and/or other apps that need to deal with things > like communication streams, it would be very handy to be able to easily > translate whatever data you have into raw bytes or turn raw bytes into the > data you want. You typically need to do this efficiently and don't want to > move the data. You can certainly get there with Unchecked_Conversion, but > this can be a pain in the ASCII and might be inefficient - requiring the > data to be moved. You can also get there by laboriously creating your own > overlays - but this can rewuire a lot of declaring if you have a lot of > things you want to treat as raw bytes. > > What about an attribute of any type that yields an array of > Ada.Streams.Stream_Element_Array ? Similarly, going in the other direction: > > for X in My_Type'Raw_Data (My_Data)'Range loop > Some_Storage_Element := My_Type'Raw_Data (My_Data) (X) ; > end loop ; > > or > > Some_Field := My_Type'Overlay (Some_Stream_Element_Array).Other_Field ; > > Maybe it should be an attribute of an Object rather than a Type? Don't know > what can be done about safety in the event that the sizes don't line up, but > I'll leave that to the compiler guys. > > I'm not fussy about the details (like the names) but it sure would be nice > to have a means of very easily, efficiently and quickly treating any object > as a stream of bytes - with the caveat being that I've just removed the > safety net (as with Unchecked_Conversion) and I can now royally shoot myself > in the foot. > > Comments? > > MDC