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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f19c50942e86e617 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: aliased variables Date: 1998/08/13 Message-ID: #1/1 X-Deja-AN: 380650828 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <35D264A8.FC025A5F@cmis.csiro.au> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1998-08-13T00:00:00+00:00 List-Id: Richard Beare (Richard.Beare@cmis.csiro.au) wrote: : I am having a problem trying to get a program with an aliased variable : to compile. I'm sure I'm missing something obvious : ------------------------------------------------- : procedure Al_Exp is : type Mt is array(Natural range <>) of Integer; : type H_Mt is access all Mt; : K : aliased Mt(1 .. 10); : L : H_Mt; : begin : L := K'Access; : end; : ------------------------------------------------- : The error message is : gcc -c -gnatv al_exp.adb : GNAT 3.10p (970814) Copyright 1992-1997 Free Software Foundation, Inc. : Compiling: al_exp.adb (source file time stamp: 1998-08-13 03:55:58) : 23. L := K'Access; : | : >>> object subtype must statically match designated subtype : What's the problem here - I haven't found anything in the RM saying I : can't have general access types pointing to unconstrained arrays - the : Rationale says that arrays of pointers to strings can be created without : dynamic allocation this way, but I haven't been able to get that to work : - what am I doing wrong? This is a nasty corner associated with 'Access on arrays. The subtypes have to match statically. This means you have to define your array object as (nominally) unconstrained to point to it with an access-to-unconstrained access value. But if it is nominally unconstrained, then it needs to be initialized. Hence, try this: K : aliased Mt := (1..10 => 0); ... ... K'Access ... Aliased discriminated types work more intuitively than do aliased arrays, for what it is worth... : Richard Beare : Richard.Beare@cmis.csiro.au -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA