comp.lang.ada
 help / color / mirror / Atom feed
From: Alexander Senier <mail@senier.net>
Subject: Re: Question about out parameters of unconstrained array type.
Date: Sun, 26 Feb 2012 00:37:53 +0100
Date: 2012-02-26T00:37:53+01:00	[thread overview]
Message-ID: <20120226003753.2f2b3224@t60> (raw)
In-Reply-To: MPG.29b336d065dea044989689@news.zen.co.uk

On Sat, 25 Feb 2012 18:20:42 -0000
Phil Thornley <phil.jpthornley@gmail.com> wrote:

> there is no syntax or semantic error reported. (You will get the usual 
> flow error if you assign individual values of the string in the loop, 
> but that's another problem all together.)
> 
> In fact the LRM states that this usage is permitted. See Section 4.1:
> "... the name of an unconstrained array object (formal parameter) shall 
> only appear in the following contexts:
>    1  as the prefix of an attribute reference;
>    2  ..."

As you say, using attributes of out parameters of an unconstrained array type
is no problem when used inside a loop iteration scheme in SPARK. However, it
seems to be when using the attribute elsewhere:

  1 package P is
  2    procedure Init (A : out String);
  3    --# derives A from ;
  4 end P;

  1 package body P is
  2    procedure Init (A : out String) is
  3    begin
  4       for I in Positive range A'First .. A'Last
  5       loop
  6          if A'Length > 42
  7          then
  8             A (I) := 'x';
  9          end if;
 10       end loop;
 11    end Init;
 12 end P;

The example yields the two expected flow errors you mention (line 8 and 11).
However, the use of A'Length in line 6 also lead to an (unexpected) flow error
(same for 'First and 'Last):

p.adb:6:13: Flow Error  20 - Expression contains reference(s) to variable A
which has an undefined value.

Regards
Alex




  parent reply	other threads:[~2012-02-25 23:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-25 15:19 Question about out parameters of unconstrained array type Peter C. Chapin
2012-02-25 15:33 ` Dmitry A. Kazakov
2012-02-25 18:20 ` Phil Thornley
2012-02-25 20:01   ` Simon Wright
2012-02-25 22:44     ` Phil Thornley
2012-02-27 13:48       ` Mark Lorenzen
2012-02-27 15:32         ` Phil Thornley
2012-02-25 23:37   ` Alexander Senier [this message]
2012-02-26  1:16   ` Peter C. Chapin
2012-02-26  9:14     ` Phil Thornley
2012-02-26 12:25       ` Alexander Senier
2012-02-26 13:20         ` Phil Thornley
2012-02-26 14:25         ` Niklas Holsti
2012-02-26 17:32         ` Jeffrey Carter
2012-02-26 15:29       ` Peter C. Chapin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox