comp.lang.ada
 help / color / mirror / Atom feed
* Dynamic allocation of unconstrained types
@ 2009-09-30 14:29 Maciej Sobczak
  2009-09-30 14:50 ` Robert A Duff
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Maciej Sobczak @ 2009-09-30 14:29 UTC (permalink / raw)


Consider:

procedure Test is

   package P is
      type T (<>) is limited private;
      function Create return T;
   private
      type T is limited record
         I : Integer;
      end record;
   end P;

   package body P is
      function Create return T is
      begin
         return T'(I => 123);
      end Create;
   end P;

   S : access P.T;

begin
   S := new P.T'(P.Create);   -- ??? (this is line 22)
end Test;

GNAT says:

test.adb:22:19: uninitialized unconstrained allocation not allowed
test.adb:22:19: qualified expression required

Interestingly, it works with Strings.
Why doesn't GNAT recognize it as a qualified expression?

I would like to allocate dynamically something that has a constructor
function. There is no other way to create the object than with that
function and presumably it should be possible to use it with dynamic
allocation.
How can I do it?

BTW - when preparing this example I tried first with empty (null)
record, but got stuck with proper way to return an instance of T. I
remember there was some older discussion about it, but for some reason
I cannot find it and the following:

return T'(others => <>);

is rejected as well.
What is the proper way to create null aggregates?

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



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

end of thread, other threads:[~2009-09-30 19:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-30 14:29 Dynamic allocation of unconstrained types Maciej Sobczak
2009-09-30 14:50 ` Robert A Duff
2009-09-30 14:54 ` Adam Beneschan
2009-09-30 18:30   ` Jeffrey R. Carter
2009-09-30 19:15     ` Adam Beneschan
2009-09-30 14:56 ` Dmitry A. Kazakov
2009-09-30 15:03   ` Adam Beneschan

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