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,1ea59bb198e88f9f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!wn13feed!worldnet.att.net!207.35.177.252!nf3.bellglobal.com!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: GNAT Ada.Streams Bug? References: <8xAqd.413508$wV.119785@attbi_s54> In-Reply-To: <8xAqd.413508$wV.119785@attbi_s54> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Mon, 29 Nov 2004 12:47:21 -0500 NNTP-Posting-Host: 198.96.223.163 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1101750379 198.96.223.163 (Mon, 29 Nov 2004 12:46:19 EST) NNTP-Posting-Date: Mon, 29 Nov 2004 12:46:19 EST Organization: Bell Sympatico Xref: g2news1.google.com comp.lang.ada:6646 Date: 2004-11-29T12:47:21-05:00 List-Id: tmoran@acm.org wrote: >>All kinds of possibilities are available when _you_ control the format. > > Anytime you need a certain external form you should plan on writing > your own 'Read et al. It may happen to work out that the default > routines supplied by the compiler do what you want, but that shouldn't > be your starting assumption. I believe this to be generally true, but I prefer not to have to do this for all records. However, efficiency is one good reason to do it (in this case, the partition table is only read at boot time). > Things with odd sizes likely won't work, > and composite objects will be inefficient. Yes. I solved my problem by avoiding the 24 bit type, but yes, I could have worked around it with a routine like you suggested. > If you use a record rep > clause to allow you to do IO on a multibyte object, you ought to write > your own 'Read et al for that object. eg: > > for Partition_Type use > record > Flags at 0 range 0..7; > CHS_Start at 1 range 0..23; > Kind at 4 range 0..7; > CHS_End at 5 range 0..23; > LBA_Start at 8 range 0..31; > LBA_Size at 12 range 0..31; > end record; > > subtype External_Partition_Type > is Ada.Streams.Stream_Element_Array(1 .. Partition_Type'size/8); > function Internalize is new Ada.Unchecked_Conversion > (Source=>External_Partition_Type, Target=>Partition_Type); > function Externalize is new Ada.Unchecked_Conversion > (Source=>Partition_Type, Target=>External_Partition_Type); > > procedure Partition_Type_Read > (Stream : access Ada.Streams.Root_Stream_Type'class; > Item : out Partition_Type) is > External : External_Partition_Type; > Last : Ada.Streams.Stream_Element_Offset; > begin > Read(Stream.all, External, Last); > if Last /= External'last then > raise ... > end if; > Item := Internalize(External); > end Partition_Type_Read; > > for Partition_Type'Read use Partition_Type_Read; > > IMHO The Unchecked_Conversion is good for safety, but I hate the inefficiency aspect of it (for partitions, as before, this is not an issue). I would probably resort to the for X'Address approach, and then use an assertion that checks that the sizes agree. Stepping back however, I still quibble that this "should" be unnecessary, unless "efficiency was the law" in that particular application. -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg