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!news.glorb.com!cyclone1.gnilink.net!spamkiller2.gnilink.net!gnilink.net!trndny04.POSTED!c2bfcbcf!not-for-mail Subject: Re: Bitmanipulation in Ada Newsgroups: comp.lang.ada References: <87k6vwrwym.fsf@insalien.org> From: "Ed Falis" Content-Type: text/plain; format=flowed; delsp=yes; charset=us-ascii MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: User-Agent: Opera M2/7.54 (Linux, build 751) Date: Thu, 19 Aug 2004 17:44:09 GMT NNTP-Posting-Host: 68.160.170.30 X-Complaints-To: abuse@verizon.net X-Trace: trndny04 1092937449 68.160.170.30 (Thu, 19 Aug 2004 13:44:09 EDT) NNTP-Posting-Date: Thu, 19 Aug 2004 13:44:09 EDT Xref: g2news1.google.com comp.lang.ada:2862 Date: 2004-08-19T17:44:09+00:00 List-Id: On 19 Aug 2004 17:30:17 GMT, Bernd Specht wrote > EF wrote: >> In all implementations of which I'm aware (and I've been in the Ada >> compiler business for over 20 years) no code would be generated for an >> unchecked conversion where the source and target have the same size. > > Sorry, but that's absolutely *nonsense* > You agree that "I" and "B" are located at different adresses? Do you > *really* think that you need *no* code to move data from one address to > another??? That's wrong! You need at least *one* instruction, and this > can > be time consuming - especially if the data is missaligned and/or the code > runs in a multiprocessor environment. I believe your original complaint was about cost of conversion, not of assignment - and this is what I was responding to. The conversion costs nothing (in the implementations I'm aware of). If you assign, you of course have at least one instruction, regardless of the types. If the conversion appeared as part of an expression being evaluated, there would be no overhead related to it. Of course, if you insist on separately-named entities, then try: with Ada.Unchecked_Conversion; procedure P is type Byte_Array is array (1 .. Integer'Size) of Boolean; pragma Pack (Byte_Array); for Byte_Array'Size use Integer'Size; function To_Byte_Array is new Ada.Unchecked_Conversion (Source => Integer, Target => Byte_Array); I : Integer := 42; B : Byte_Array renames To_Byte_Array (I); begin null; end P; Compile some code and take a look at the generated assembly language. - Ed