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: 103376,3a7c118fd2cc64f9 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!s14g2000vbi.googlegroups.com!not-for-mail From: AdaMagica Newsgroups: comp.lang.ada Subject: Re: A hole in Ada type safety Date: Wed, 11 May 2011 22:51:19 -0700 (PDT) Organization: http://groups.google.com Message-ID: <6fc0d396-40ca-4f32-8840-8091b94d9ddf@s14g2000vbi.googlegroups.com> References: <87oc3odtci.fsf@mid.deneb.enyo.de> <715a5498-095c-4e61-8a09-8510c19b2553@s16g2000prf.googlegroups.com> NNTP-Posting-Host: 80.156.44.178 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1305179479 16519 127.0.0.1 (12 May 2011 05:51:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 12 May 2011 05:51:19 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s14g2000vbi.googlegroups.com; posting-host=80.156.44.178; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:20202 Date: 2011-05-11T22:51:19-07:00 List-Id: Randy has already given the answer. Let me add a further remark (but note, I'm no language lawyer): You argue about the return statement. But there is no return statement involved in the RM with Unchecked_Conversion, it's just compiler magic that is being performed. (Being intrinsic, Unchecked_Conversion need not be implemented in Ada. In fact, I think there is no code at all, it just takes the bit pattern as is and reinterpretes it.) Run the following test program: package UC is type LP1 is limited private; procedure Set (X: out LP1; to: Integer); type LP2 is limited private; private type LP1 is limited record I: Integer := 1234; end record; type LP2 is limited record I: Integer := Integer'First; end record; end UC; package body UC is procedure Set (X: out LP1; to: Integer) is begin X.I := to; end Set; end UC; with Ada.Text_IO; with Ada.Unchecked_Conversion; with UC; procedure Test_UC is function LP1_LP2 is new Ada.Unchecked_Conversion (UC.LP1, UC.LP2); function LP2_I is new Ada.Unchecked_Conversion (UC.LP2, Integer); X: UC.LP1; Y: constant UC.LP2 := LP1_LP2 (X); -- new object built in place Z: UC.LP2 renames LP1_LP2 (X); -- read-only view begin -- expected result Ada.Text_IO.Put_Line (Integer'Image (LP2_I (Y)) & Integer'Image (LP2_I (Z))); -- 1234 1234 UC.Set (X, -100); Ada.Text_IO.Put_Line (Integer'Image (LP2_I (Y)) & Integer'Image (LP2_I (Z))); -- 1234-100 end Test_UC;