comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <PChapin@vtc.vsc.edu>
Subject: Re: Question about out parameters of unconstrained array type.
Date: Sat, 25 Feb 2012 20:16:04 -0500
Date: 2012-02-25T20:16:04-05:00	[thread overview]
Message-ID: <4NedncPWdPN9GtTS4p2dnAA@giganews.com> (raw)
In-Reply-To: <MPG.29b336d065dea044989689@news.zen.co.uk>

On 2012-02-25 13:20, Phil Thornley wrote:

> I think that you may be misinterpreting the SPARK error message:
>
>    15        for I in 1 .. S'Length loop
>                       ^
> ***        Syntax Error      : reserved word "IN" cannot be followed by
>             INTEGER_NUMBER here.
>
> The error here is that the loop index has an anonymous subtype.

I'm sorry to have distracted you with my silly error. That's what 
happens when one just types some code into a posting off the top of 
one's head.

My real code is more like this:

procedure Get_Event
    (Date        : in  Dates.Date;
     Description : out String;
     Status      : out Status_Type)
--# global in Event_Array;
--# derives Description from Event_Array, Date &
--#         Status      from Event_Array, Date;
is
    I : Event_Index_Type;
begin
    Status      := No_Event;
    Description := (others => ' ');   -- NOTE HERE [1]

    I := Event_Index_Type'First;
    loop
       -- Is this item in the event array the one we are looking for?
       if Event_Array(I).Date = Date then
          -- NOTE HERE [2]
          if Description'Length < Event_Array(I).Description_Size then
             Status := Description_Too_Long;
          else
             -- Copy Event_Array(I).Description_Text into Description
             Status := Success;
          end if;
          exit;
       end if;

       -- If not, then advance to the next item.
       exit when I = Event_Index_Type'Last;
       I := I + 1;
    end loop;
end Get_Event;

Without the initialization at [1] the use of Description'Length at [2] 
produces the error Alexander mentions: "Expression contains reference(s) 
to variable Description which has an undefined value."

However with the initialization at [1] this error goes away. Thus it 
appears that SPARK requires that the initial value be defined before it 
will let you use the attributes.

Peter



  parent reply	other threads:[~2012-02-26  1:16 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
2012-02-26  1:16   ` Peter C. Chapin [this message]
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