comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Belmont <sbelmont700@gmail.com>
Subject: GNAT - return by anonymous access
Date: Sat, 17 Dec 2011 11:17:20 -0800 (PST)
Date: 2011-12-17T11:17:20-08:00	[thread overview]
Message-ID: <784c67eb-a542-41b0-b23d-fca1234e56b2@n10g2000vbg.googlegroups.com> (raw)


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;



             reply	other threads:[~2011-12-17 19:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-17 19:17 Simon Belmont [this message]
2011-12-17 19:51 ` GNAT - return by anonymous access Simon Wright
2011-12-18  9:08 ` Georg Bauhaus
2011-12-19 23:46 ` Randy Brukardt
2011-12-20  0:14   ` Shark8
2011-12-20 23:18     ` Randy Brukardt
2011-12-21  0:44       ` Simon Belmont
2011-12-21  7:29         ` AdaMagica
2011-12-21 11:05           ` Georg Bauhaus
2011-12-21 11:43             ` AdaMagica
2011-12-21 12:05               ` Georg Bauhaus
2011-12-22  0:33                 ` Randy Brukardt
2011-12-22  0:33           ` Simon Belmont
2011-12-22  7:11             ` Adam Beneschan
2011-12-22 22:11               ` Simon Belmont
2011-12-23  0:56                 ` Randy Brukardt
2011-12-23 13:20                   ` Simon Belmont
2011-12-27 23:51                     ` Randy Brukardt
2011-12-20 23:53 ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox