comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Dynamic allocation of unconstrained types
Date: Wed, 30 Sep 2009 10:50:05 -0400
Date: 2009-09-30T10:50:05-04:00	[thread overview]
Message-ID: <wcceipoa3mq.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: dd95bb9b-7604-4347-a964-2108502cf4c8@37g2000yqm.googlegroups.com

Maciej Sobczak <see.my.homepage@gmail.com> writes:

> 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;

I try to avoid the use of anonymous access types.
They cause too many surprises.

> 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

Looks like a bug in the compiler.

> 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 => <>);

    return (null record);

or 

    return T'(null record);

The "others => <>" should work, too.

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

- Bob



  reply	other threads:[~2009-09-30 14:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-30 14:29 Dynamic allocation of unconstrained types Maciej Sobczak
2009-09-30 14:50 ` Robert A Duff [this message]
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