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,a9b0810d3106d9b8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!feeder.erje.net!news-2.dfn.de!news.dfn.de!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sun, 17 Apr 2011 09:17:37 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Fun with C References: <27cf3992-4132-4483-9110-adc7a089cd4a@e8g2000vbz.googlegroups.com> <8762qdyk6y.fsf@ludovic-brenta.org> In-Reply-To: <8762qdyk6y.fsf@ludovic-brenta.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4daa9411$0$7658$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 17 Apr 2011 09:17:37 CEST NNTP-Posting-Host: 3a15629c.newsspool1.arcor-online.net X-Trace: DXC=]kdcAd=46RHgj[ZPFj7ehOic==]BZ:afN4Fo<]lROoRA<`=YMgDjhgBI3?B2M?cZ7GPCY\c7>ejVHRFUgmnd@0eahLJ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:18829 Date: 2011-04-17T09:17:37+02:00 List-Id: On 4/16/11 11:12 PM, Ludovic Brenta wrote: > "Nasser M. Abbasi" writes: >> $ gcc -Wall t.c >> $ ./a.out >> R = 33554416 > > So R = 2**25 - 16, the correct answer is -16, so the actual result is > the correct one except for bit 24, which is 1 when it should be zero. > > Out of curiosity, is this actual result a predictable consequence of the > language definition, or is it undefined behavior? Why, it is the same in Ada. with Ada.Text_IO; use Ada.Text_IO; with Ada.Unchecked_Conversion; procedure Conv is type UInt is mod 2**32; type Int is range -2**31 .. 2**31 -1; function To_UInt is new Ada.Unchecked_Conversion(Int, UInt); N: UInt := 128; I: Int := -2048; R : Int; begin R := Int(To_UInt(I) / N); Put_Line ("R =" & Int'Image(R)); end;