comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: stream_element array contiguity
Date: Fri, 27 Jun 2003 18:20:32 GMT
Date: 2003-06-27T18:20:32+00:00	[thread overview]
Message-ID: <3EFC8ABD.7020105@attbi.com> (raw)
In-Reply-To: abac65e4.0306270907.60d7f10f@posting.google.com

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.




  reply	other threads:[~2003-06-27 18:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-27 17:07 stream_element array contiguity Ian Leroux
2003-06-27 18:20 ` Robert I. Eachus [this message]
2003-06-27 18:29 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox