comp.lang.ada
 help / color / mirror / Atom feed
* Limited_Controlled and constructor functions
@ 2007-01-18  9:51 Maciej Sobczak
  2007-01-18 12:13 ` AW: " Grein, Christoph (Fa. ESG)
  2007-01-18 16:41 ` Robert A Duff
  0 siblings, 2 replies; 10+ messages in thread
From: Maciej Sobczak @ 2007-01-18  9:51 UTC (permalink / raw)


Hi,

Consider another Limited_Controlled problem:

-- p.ads:
with Ada.Finalization;
package P is
    type T (<>) is private;
    function Constructor(I : Integer) return T;
private
    type Array_Of_Ints is array (Positive range <>) of Integer;
    type T (Size : Positive) is new Ada.Finalization.Controlled with
       record
          A : Array_Of_Ints(1..Size);
       end record;
end P;

-- p.adb:
package body P is
    function Constructor(I : Integer) return T is
    begin
       return T'(Ada.Finalization.Controlled with
                 Size => 1, A => (1 => I));
    end Constructor;
end P;

It looks a bit convoluted. :-)
The idea is to have a T type that contains the array of integers and a 
constructor function that creates T with single element in the contained 
array. T is private, controlled and indefinite, to force the use of 
constructor function whenever T is declared.

Now, I want to make it limited as well by adding limited before private 
and changing Controlled to Limited_Controlled in two places.
I get this when compiling the package:

cannot return a local value by reference
"Program_Error" will be raised at run time

What's going on?

-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



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

end of thread, other threads:[~2007-01-22  8:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-18  9:51 Limited_Controlled and constructor functions Maciej Sobczak
2007-01-18 12:13 ` AW: " Grein, Christoph (Fa. ESG)
2007-01-18 16:41 ` Robert A Duff
2007-01-19  7:58   ` Maciej Sobczak
2007-01-19  9:41     ` Dmitry A. Kazakov
2007-01-19 13:45       ` Maciej Sobczak
2007-01-19 14:33         ` Dmitry A. Kazakov
2007-01-22  8:59           ` Maciej Sobczak
2007-01-20 17:09     ` Gautier
2007-01-20 19:39       ` Gautier

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