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=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,68536605ede13a20 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.74.201 with SMTP id w9mr3211422pbv.0.1324425239741; Tue, 20 Dec 2011 15:53:59 -0800 (PST) MIME-Version: 1.0 Path: lh20ni45881pbb.0!nntp.google.com!news1.google.com!goblin1!goblin.stu.neva.ru!news.ett.com.ua!not-for-mail From: anon@att.net Newsgroups: comp.lang.ada Subject: Re: GNAT - return by anonymous access Date: Tue, 20 Dec 2011 23:53:58 +0000 (UTC) Organization: ETT newsserver Message-ID: References: <784c67eb-a542-41b0-b23d-fca1234e56b2@n10g2000vbg.googlegroups.com> Reply-To: anon@anon.org NNTP-Posting-Host: dialup-4.225.168.164.dial1.dallas1.level3.net X-Complaints-To: usenet@news.ett.com.ua X-Notice: Filtered by postfilter v. 0.6.1 X-Newsreader: IBM NewsReader/2 2.0 Date: 2011-12-20T23:53:58+00:00 List-Id: A corrected version, that works! Just made a few changes in the code. First GNAT does not like the "access Integer", define a Integer_Access type. Second, "limited" was remove because of the error message "cannot initialize entities of limited type". Third, I use an "Use" Statement in "test_driver.adb" instead of using of "test_package.". -- Unit 1 package test_package is type Integer_Access is access all Integer ; type test_type (p_obj : Integer_Access) is private; function get return test_type; private type test_type (p_obj : Integer_Access) is null record ; end test_package; -- Unit 2 package body test_package is function get return test_type is begin return test_type ' ( p_obj => new Integer'(42) ); end get; end test_package; -- Unit 3 with test_package; with Text_IO; use test_package; procedure test_driver is foo : test_type := test_package.get; -- Removed : '42' (expected) -- Present : '4409264' bar : Integer_Access := new Integer'(69); begin Text_IO.Put_Line(foo.p_obj.all'img); end test_driver; In <784c67eb-a542-41b0-b23d-fca1234e56b2@n10g2000vbg.googlegroups.com>, Simon Belmont writes: > >This ostensibly simple program prints strange results, and i'm rapidly >losing faith in the GNAT compiler (GNAT GPL 20110428). If anyone with >an alternative compiler can confirm or deny this output as spurious, I >would be much obliged. In short, when the declaration of 'bar' is >commented out, the program behaves as i would expect (output is '42'), >but when bar is present, the output is much different (output is >'4409264'). Or, if my line of reasoning is mixed up and this is >actually the appropriate behavior, I would be grateful for any >explanation. > >Thank you again > >-sb > >-- Unit 1 >package test_package is > type test_type (p_obj : access Integer) is limited private; > function get return test_type; > >private > type test_type (p_obj : access Integer) is limited null record; > >end test_package; > >-- Unit 2 >package body test_package is > > function get return test_type is > begin > return test_type'(p_obj => new Integer'(42)); > end get; > >end test_package; > >-- Unit 3 >with test_package; >with Text_IO; > >procedure test_driver is > > foo : test_package.test_type := test_package.get; > > -- Removed : '42' (expected) > -- Present : '4409264' > bar : access Integer := new Integer'(69); > >begin > > Text_IO.Put_Line(foo.p_obj.all'img); > >end test_driver;