From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Dynamic allocation of unconstrained types
Date: Wed, 30 Sep 2009 07:29:26 -0700 (PDT)
Date: 2009-09-30T07:29:26-07:00 [thread overview]
Message-ID: <dd95bb9b-7604-4347-a964-2108502cf4c8@37g2000yqm.googlegroups.com> (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
next reply other threads:[~2009-09-30 14:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-30 14:29 Maciej Sobczak [this message]
2009-09-30 14:50 ` Dynamic allocation of unconstrained types 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox