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,235763d9b1b2155a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-27 11:20:34 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn12feed!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc04.POSTED!not-for-mail Message-ID: <3EFC8ABD.7020105@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: stream_element array contiguity References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.62.164.137 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc04 1056738005 24.62.164.137 (Fri, 27 Jun 2003 18:20:05 GMT) NNTP-Posting-Date: Fri, 27 Jun 2003 18:20:05 GMT Organization: AT&T Broadband Date: Fri, 27 Jun 2003 18:20:32 GMT Xref: archiver1.google.com comp.lang.ada:39844 Date: 2003-06-27T18:20:32+00:00 List-Id: Ian Leroux wrote: > From reading previous posts, I gather that a common approach to > dealing with bitwise input is to use Unchecked_Conversion to transform > to packed arrays of Boolean from arrays of Stream_Element, obtained > from an appropriate Stream package. Given that Stream_Element'Size is > not guaranteed to be a multiple or factor of Storage_Element'Size, is > there any way of being sure that the elements of a Stream_Element > array will be contiguous? If not, is there any standard way of > avoiding the problem whereby padding bits in the Stream_Element array > corrupt the resulting boolean array? > > I realize that on most compilers and platforms this is unlikely to be > a real issue, but I'm wondering if there is any way to be sure (since > being sure about this sort of thing is one of the features I find > appealing about Ada). > > I am a newcomer to the language, and would be glad to be called on any > factual errors in this post. It would be possible to write Ada code to correctly deal with this case, and not all that difficult. But the code would invovle assigning bit slices, and the efficiency of that code would be compiler dependent. In most areas I would tell you to trust the optimizer, but in this case I would probably write: pragma Assert(Storage_Element'Size mod Stream_Element'Size = 0); or whatever the actual assumption in your code is, even paragma Assert(Storage_Element'Size = Stream_Element'Size); I really don't think I'd like to try to get the code right for the more general case unless I had an implementation that I could correctly test the code on.