comp.lang.ada
 help / color / mirror / Atom feed
* GNAT - return by anonymous access
@ 2011-12-17 19:17 Simon Belmont
  2011-12-17 19:51 ` Simon Wright
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Simon Belmont @ 2011-12-17 19:17 UTC (permalink / 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;



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2011-12-27 23:51 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-17 19:17 GNAT - return by anonymous access Simon Belmont
2011-12-17 19:51 ` 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

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