comp.lang.ada
 help / color / mirror / Atom feed
From: Dan <dan@irvine.com>
Subject: Re: Problem where a function is invoked once but called twice (when invocation is within an allocator).
Date: Wed, 11 May 2011 10:23:28 -0700 (PDT)
Date: 2011-05-11T10:23:28-07:00	[thread overview]
Message-ID: <a897466a-02c6-4bbd-a546-ea5bb34555fb@q14g2000prh.googlegroups.com> (raw)
In-Reply-To: 7333adc4-3b87-48cb-902a-bff11d062b6a@v8g2000yqb.googlegroups.com

Here's a version of the test case that fails in Ada83 mode.


package Media is

   type Color is
      record
         val : integer;
      end record;

   type Image is array (integer range <>) of Color;
   pragma pack (Image);         -- matters!

   function next_Frame return Image;

   type Image_ptr is access Media.Image;

end Media;

with Text_IO; use Text_IO;
package body Media is
   counter: integer := 0;

   function next_Frame return Image is
   begin
      put_line("in next_frame");
      counter := counter + 1;
      return (1 .. 5-counter => (val => 10));
   end next_Frame;

end Media;



with Media;
with text_io;
procedure Test2 is

   Case_1 : Media.Image(1..4) :=     Media.Image' (Media.next_Frame);
   Case_2 : Media.Image_ptr   := new Media.Image' (Media.next_Frame);

   procedure put(x: Media.Image) is
   j: integer;
   begin
     for i in x'range loop
        text_io.put_line(x(i).val'img);
        j := 1/x(i).val;        -- ensure val is not zero
     end loop;
     text_io.new_line;
   end;

begin
   put(case_1);
   put(case_2.all);
end;



  reply	other threads:[~2011-05-11 17:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-05  3:52 Problem where a function is invoked once but called twice (when invocation is within an allocator) Rod Kay
2011-05-05  5:43 ` J-P. Rosen
2011-05-05  6:12   ` Rod Kay
2011-05-05  8:22   ` Yannick Duchêne (Hibou57)
2011-05-05 10:59     ` Rod Kay
2011-05-05 17:07       ` Florian Weimer
2011-05-06  0:49         ` Rod Kay
2011-05-06 23:41           ` Anh Vo
2011-05-07  1:38             ` Rod Kay
2011-05-07  9:06               ` Georg Bauhaus
2011-05-07  9:45                 ` Rod Kay
2011-05-09 16:01               ` Anh Vo
2011-05-09 23:00                 ` Dan
2011-05-10  0:14                   ` Anh Vo
2011-05-10  0:24                     ` Rod Kay
2011-05-10  0:55                       ` Anh Vo
2011-05-11 17:23                         ` Dan [this message]
2011-05-12 22:35                         ` Rod Kay
2011-05-13 17:40                           ` Ludovic Brenta
2011-05-10  0:21                   ` Rod Kay
  -- strict thread matches above, loose matches on Subject: below --
2011-05-14  0:27 Rod Kay
replies disabled

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