* aliased variables
@ 1998-08-13 0:00 Richard Beare
1998-08-13 0:00 ` David C. Hoos, Sr.
1998-08-13 0:00 ` Tucker Taft
0 siblings, 2 replies; 4+ messages in thread
From: Richard Beare @ 1998-08-13 0:00 UTC (permalink / raw)
Hi,
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?
--
Richard Beare
Richard.Beare@cmis.csiro.au
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: aliased variables
1998-08-13 0:00 aliased variables Richard Beare
1998-08-13 0:00 ` David C. Hoos, Sr.
@ 1998-08-13 0:00 ` Tucker Taft
1998-08-14 0:00 ` Robert Dewar
1 sibling, 1 reply; 4+ messages in thread
From: Tucker Taft @ 1998-08-13 0:00 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: aliased variables
1998-08-13 0:00 aliased variables Richard Beare
@ 1998-08-13 0:00 ` David C. Hoos, Sr.
1998-08-13 0:00 ` Tucker Taft
1 sibling, 0 replies; 4+ messages in thread
From: David C. Hoos, Sr. @ 1998-08-13 0:00 UTC (permalink / raw)
Richard Beare wrote in message <35D264A8.FC025A5F@cmis.csiro.au>...
>Hi,
>I am having a problem trying to get a program with an aliased variable
>to compile. I'm sure I'm missing something obvious
The problem is that your program does not conform to the rule expresssed in
the following sentence of RM 3.10 (9):
If the view defined by an object_declaration is aliased, and the type of the
object has discriminants, then the object is constrained; if its nominal
subtype is unconstrained, then the object is constrained by its initial
value.
Since K's nominal subtype is unconstrained, the object must be constrained
not by explicit bounds, but by its initial value.
The solution is to declare K as follows:
K : aliased Mt := (1 .. 10 => 0);
David C. Hoos, Sr.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: aliased variables
1998-08-13 0:00 ` Tucker Taft
@ 1998-08-14 0:00 ` Robert Dewar
0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1998-08-14 0:00 UTC (permalink / raw)
Richard may like better the error messages that come out of the latest
version of
GNAT:
1. procedure Al_Exp is
2.
3. type Mt is array(Natural range <>) of Integer;
4.
5. type H_Mt is access all Mt;
6.
7. K : aliased Mt(1 .. 10);
|
>>> warning: aliased object has explicit bounds
>>> warning: declare with explicit initialization
>>> warning: for use with unconstrained access
8. L : H_Mt;
9.
10. begin
11. L := K'Access;
|
>>> object subtype must statically match designated subtype
12. end;
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1998-08-14 0:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-08-13 0:00 aliased variables Richard Beare
1998-08-13 0:00 ` David C. Hoos, Sr.
1998-08-13 0:00 ` Tucker Taft
1998-08-14 0:00 ` Robert Dewar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox