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:28:07 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: stream_element array contiguity Date: Fri, 27 Jun 2003 13:29:26 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Newsreader: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3719.2500 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:39845 Date: 2003-06-27T13:29:26-05:00 List-Id: 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.