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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,804404553c230a79 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.224.31.20 with SMTP id w20mr9587571qac.2.1348914161785; Sat, 29 Sep 2012 03:22:41 -0700 (PDT) Received: by 10.52.30.164 with SMTP id t4mr2363218vdh.4.1348914161748; Sat, 29 Sep 2012 03:22:41 -0700 (PDT) Path: e10ni119047168qan.0!nntp.google.com!l8no16538689qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 29 Sep 2012 03:22:41 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=91.7.109.137; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf NNTP-Posting-Host: 91.7.109.137 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <7611a745-1290-4957-91b6-289ba97abf13@googlegroups.com> Subject: Re: ANN: AdaTutor on the Web - done From: AdaMagica Injection-Date: Sat, 29 Sep 2012 10:22:41 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-09-29T03:22:41-07:00 List-Id: This text in the tutorial about UC is nonsense: One use of Ada.Unchecked_Conversion might be to allow us to and two Integer= s. (Ada 95 allows us to and two objects of a modular type, but not two Int= egers.) Some Ada compilers come with a package that enables us to and two I= ntegers, but many compilers have no such package. Suppose that types Integ= er and Boolean occupy the same amount of storage. If our program says with= Ada.Unchecked_Conversion; we could write function Int_To_Bool is new Ada.Unchecked_Conversion(Integer, Boolean); function Bool_To_Int is new Ada.Unchecked_Conversion(Boolean, Integer); function "and"(Left, Right : in Integer) return Integer is begin return Bool_To_Int(Int_To_Bool(Left) and Int_To_Bool(Right)); end "and"; Integer and Boolean have never the same size. Boolean'Size =3D 1. "and" wil= l pick either the MSB or the LSB of Left and Right, depending on compiler r= esp. hardware. (Ada83 was a bit unclear about the meaning of 'Size, there are differences = in the behaviour of compilers. Ada95 fixed that - in a way that some find a= wkward.) UC between Integer and Natural might work or include a multiplication/divis= ion by 2 because Natural'Size=3DInteger'Size-1. I have been bitten by UC be= tween objects of types with different sizes when porting some legacy Ada83 = code to a different hardware and compiler. Be careful: Stand-along objects = of subtype Natural and of Integer have of course the same size - what matte= rs for UC is the subtype's size, which is given by 'Size - this is why GNAT= has an attribute 'Object_Size.