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,9dec3ff1604723d9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 MSIE X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Bitmanipulation in Ada References: <87k6vwrwym.fsf@insalien.org> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 19 Aug 2004 00:53:48 GMT NNTP-Posting-Host: 63.184.104.217 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1092876828 63.184.104.217 (Wed, 18 Aug 2004 17:53:48 PDT) NNTP-Posting-Date: Wed, 18 Aug 2004 17:53:48 PDT Xref: g2news1.google.com comp.lang.ada:2828 Date: 2004-08-19T00:53:48+00:00 List-Id: Bernd Specht wrote: > Ok. Is there a reason why it is not (directly) available in the > language itself like the and/or/xor or the >> and << in C? Shift and rotate operations only make sense for types that are a "natural" size for the underlying hardware. Those are the only kind of integer types available in C. Since Ada also provides user-defined numeric types, which may not be a natural size for the hardware, these can only be provided for types which are a natural size. > OK, but this would result in an assignment operation (a memory move > on maschine code level). What I want is a real "overlay" (same > storage location used for both), so reading the value would not need > extra instructions. That may be what you want. What a software engineer wants is the clearest software that meets the requirements. Unchecked_Conversion will almost always provide this. In many cases, Unchecked_Conversion will generate no code, and need not involve an assignment. In well designed software, the part(s) of the software that deals with values as an integer and those that deal with them as bit arrays will be kept separate. So you do something like: with Ada.Unchecked_Conversion; procedure Deals_2_Ways is type Bit_Array is array (1 .. Integer'Size) of Boolean; pragma Pack (Bit_Array); for Bit_Array'Component_Size use 1; for Bit_Array'Size use Integer'Size; function Get return Integer is separate; Value : Integer := Get; procedure Deal_With_Integer (Value : in out Integer) is separate; procedure Deal_With_Bit_Array (Value : in out Bit_Array) is separate; function To_Bit is new Ada.Unchecked_Conversion (Source => Integer, Target => Bit_Array); begin -- Deals_2_Ways Deal_With_Integer (Value => Value); Deal_With_Bit_Array (Value => To_Bit (Value) ); end Deals_2_Ways; -- Jeff Carter "I'm particularly glad that these lovely children were here today to hear that speech. Not only was it authentic frontier gibberish, it expressed a courage little seen in this day and age." Blazing Saddles 88