comp.lang.ada
 help / color / mirror / Atom feed
* Problem with anonymous arrays
@ 2004-04-24 22:46 Delf
  2004-04-24 23:26 ` Lutz Donnerhacke
  2004-04-25  8:10 ` Delf
  0 siblings, 2 replies; 6+ messages in thread
From: Delf @ 2004-04-24 22:46 UTC (permalink / raw)


Hi.
I've got a little problem:

/CODE/
...
   N: constant Integer := 4;

   protected Choice is
      entry EnterOnRP (I: Integer);
      procedure ExitTheRP;
   private
      WhoCanPass: Integer := -1;
      MAXCARS: Integer := 5;
      NbCarsOnRP: Integer := 0;
      WantToGo: array(0..(N - 1)) of Boolean := (0..(N - 1) => FALSE);
   end Choice;
...
\CODE\

When I compile, I obtain the following message:
Giratoire.adb:17:17: anonymous arrays not allowed as components

What I have to modify ?
Thanks a lot.

--
Delf



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with anonymous arrays
  2004-04-24 22:46 Problem with anonymous arrays Delf
@ 2004-04-24 23:26 ` Lutz Donnerhacke
  2004-04-25  0:29   ` Delf
  2004-04-25  8:10 ` Delf
  1 sibling, 1 reply; 6+ messages in thread
From: Lutz Donnerhacke @ 2004-04-24 23:26 UTC (permalink / raw)


* Delf wrote:
>    N: constant Integer := 4;
>
>    protected Choice is
>       entry EnterOnRP (I: Integer);
>       procedure ExitTheRP;
>    private
>       WhoCanPass: Integer := -1;
>       MAXCARS: Integer := 5;
>       NbCarsOnRP: Integer := 0;
>       WantToGo: array(0..(N - 1)) of Boolean := (0..(N - 1) => FALSE);
>    end Choice;
>
> When I compile, I obtain the following message:
> Giratoire.adb:17:17: anonymous arrays not allowed as components
>
> What I have to modify ?

type Bool_Array is array (0 .. (N-1) of Boolean;
protected type Choice is
  ...
  WantToGo : Bool_Array := (others => False);
end Choice;



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with anonymous arrays
  2004-04-24 23:26 ` Lutz Donnerhacke
@ 2004-04-25  0:29   ` Delf
  0 siblings, 0 replies; 6+ messages in thread
From: Delf @ 2004-04-25  0:29 UTC (permalink / raw)


Le Sat, 24 Apr 2004 23:26:53 +0000, Lutz Donnerhacke a ecrit:

> type Bool_Array is array (0 .. (N-1) of Boolean;
> protected type Choice is
>   ...
>   WantToGo : Bool_Array := (others => False);
> end Choice;

Thanks for your help.

--
Delf



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with anonymous arrays
  2004-04-24 22:46 Problem with anonymous arrays Delf
  2004-04-24 23:26 ` Lutz Donnerhacke
@ 2004-04-25  8:10 ` Delf
  2004-04-25 17:58   ` Lutz Donnerhacke
  2004-04-25 18:01   ` Lutz Donnerhacke
  1 sibling, 2 replies; 6+ messages in thread
From: Delf @ 2004-04-25  8:10 UTC (permalink / raw)


Le Sun, 25 Apr 2004 00:46:34 +0200, Delf a ecrit:

> /CODE/
> ...
>    N: constant Integer := 4;
> 
>    protected Choice is
>       entry EnterOnRP (I: Integer);
>       procedure ExitTheRP;
>    private
>       WhoCanPass: Integer := -1;
>       MAXCARS: Integer := 5;
>       NbCarsOnRP: Integer := 0;
>       WantToGo: array(0..(N - 1)) of Boolean := (0..(N - 1) => FALSE);
>    end Choice;
> ...
> \CODE\

+ line 

entry EnterGiratoire (I: Integer) when NbCarsOnRP = 0 or (NbCarsOnRP > 0 and NbCarsOnRP < MAXCARS and I = WhoCanPass) is

But gnatmake says: Giratoire.adb:35:109: "I" is undefined

So I can't use I... How to do to counter this error ?
Thanks.

--
Delf



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with anonymous arrays
  2004-04-25  8:10 ` Delf
@ 2004-04-25 17:58   ` Lutz Donnerhacke
  2004-04-25 18:01   ` Lutz Donnerhacke
  1 sibling, 0 replies; 6+ messages in thread
From: Lutz Donnerhacke @ 2004-04-25 17:58 UTC (permalink / raw)


* Delf wrote:
> entry EnterGiratoire (I: Integer) when NbCarsOnRP = 0 or (NbCarsOnRP > 0
> and NbCarsOnRP < MAXCARS and I = WhoCanPass) is
>
> But gnatmake says: Giratoire.adb:35:109: "I" is undefined

I is defined AFTER the guard is passed.
If you like to access parameters TO the guard you have to use entry families:

type Family is range 1 .. 16;
protected type XXX is
  entry EnterGiratoire(Family)(other: Parameter);
end XXX;

protected body XXX is
  entry EnterGiratoire(for I in Family)(other : Parameter)
   when ... I = WhoCanPass is
  begin
     ...
  end EnterGiratoire;
end XXX;

Please note, that entry families can be instantiated as separate procedures
for each possible value of the family parameter. So the usable range of
values is limited. GNAT allows the whole Integer range, but fails miserably
in instantiating with Storage_Error.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with anonymous arrays
  2004-04-25  8:10 ` Delf
  2004-04-25 17:58   ` Lutz Donnerhacke
@ 2004-04-25 18:01   ` Lutz Donnerhacke
  1 sibling, 0 replies; 6+ messages in thread
From: Lutz Donnerhacke @ 2004-04-25 18:01 UTC (permalink / raw)


* Delf wrote:
> entry EnterGiratoire (I: Integer) when NbCarsOnRP = 0 or (NbCarsOnRP > 0
> and NbCarsOnRP < MAXCARS and I = WhoCanPass) is
>
> But gnatmake says: Giratoire.adb:35:109: "I" is undefined

I is defined AFTER the guard is passed.
If you like to provide parameters TO the guard you have to use entry families:

type Family is range 1 .. 16;
protected type XXX is
  entry EnterGiratoire(Family)(other: Parameter);
end XXX;

protected body XXX is
  entry EnterGiratoire(for I in Family)(other : Parameter)
   when ... I = WhoCanPass is
  begin
     ...
  end EnterGiratoire;
end XXX;

Please note, that entry families can be instantiated as separate procedures
for each possible value of the family parameter. So the usable range of
values is limited. GNAT allows the whole Integer range, but fails miserably
in instantiating with Storage_Error.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-04-25 18:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-24 22:46 Problem with anonymous arrays Delf
2004-04-24 23:26 ` Lutz Donnerhacke
2004-04-25  0:29   ` Delf
2004-04-25  8:10 ` Delf
2004-04-25 17:58   ` Lutz Donnerhacke
2004-04-25 18:01   ` Lutz Donnerhacke

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