From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,ba1efd580c7c1290,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!37g2000yqm.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Dynamic allocation of unconstrained types Date: Wed, 30 Sep 2009 07:29:26 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 137.138.182.236 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1254320966 26576 127.0.0.1 (30 Sep 2009 14:29:26 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 30 Sep 2009 14:29:26 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 37g2000yqm.googlegroups.com; posting-host=137.138.182.236; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8538 Date: 2009-09-30T07:29:26-07:00 List-Id: 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