comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: stream_element array contiguity
Date: Fri, 27 Jun 2003 13:29:26 -0500
Date: 2003-06-27T13:29:26-05:00	[thread overview]
Message-ID: <vfp35gqpalp078@corp.supernews.com> (raw)
In-Reply-To: abac65e4.0306270907.60d7f10f@posting.google.com

Ian Leroux wrote in message ...
>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 generally just put in a check at elaboration time that the assumptions
of the code are not violated. For instance, if you assumed that
Stream_Element'Size = Storage_Element'Size, then I'd put:

   if Stream_Element'Size /= Storage_Element'Size then
      raise Program_Error;
   end if;

into the "begin" part of the package body. If this somehow gets
violated, you hopefully will get a warning, but certainly will get a
Program_Error on the first test. (If no one bothers to run a test, like
the Ariene 5, well, not much can help that project).

What the condition will be depends on the details of your code, of
course. I often have code that looks like:
    Item_Size : constant := 8;
    ...
    if Some_Type'Size /= Item_Size then
     raise Program_Error;
   end if;
because "Some_Type'Size" isn't static, and thus cannot be used directly
in representation clauses. But we want to make sure that the rep.
clauses are accurate. (It won't do to have the size actually be 6 or
12.)

           Randy.





      parent reply	other threads:[~2003-06-27 18:29 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
2003-06-27 18:29 ` Randy Brukardt [this message]
replies disabled

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