From: Robert A Duff <bobduff@world.std.com>
Subject: Re: "recursive" accept statement ??
Date: 1998/12/23
Date: 1998-12-23T00:00:00+00:00 [thread overview]
Message-ID: <wccempqzwjo.fsf@world.std.com> (raw)
In-Reply-To: 1998Dec15.122957@lri.fr
fv@lri.fr (Frederic Voisin) writes:
> with Ada.text_io ; use Ada.text_io ;
>
> procedure Biz is
>
> task trace is
> entry put(str : string) ;
> end trace ;
>
> task body trace is
> begin
> accept Put (str : string) do
> Ada.text_io.put(str); -- works fine
> Put(Str); -- behave like trace.Put(str) ????
The above "Put" refers to the entry, not to the procedure in Text_IO.
So it deadlocks. The entry hides the other declaration of Put.
> When compiled with GNAT (gnat-3.10p on a Solaris machine) I get only the first
> 'Hello World" but not the second ...
And then it deadlocked, right?
> If allowed, what is the rationale behind, since such construct is much
> error-proned
> (and I had a hard time finding it)
Yes, I agree that hiding is error-prone. I would prefer a rule that
made the above ambiguous (and therefore illegal).
The issue isn't accept statements, in particular. You could have a
similar example with only procedures involved, and one procedure might
hide the one you *meant* to call.
Or something similar could happen with variable declarations,
or anything else.
Hiding causes something very similar to the "Beaujolais effect".
It is possible to insert a declaration into a working program, and have
it change its meaning, but still be legal. That's a bad thing.
Hiding is really a "preference rule" -- inner things are preferred over
outer things and use-visible things. And preference rules often cause
Beaujolais effects -- or in this case, something analogous.
> Shouldn't it deserve a warning ?? or a complain about ambiguity ?
The problem with warnings is that they're not standard. It's not clear
(to the compiler writer, nor to the programmer) exactly which cases
should be warned about.
It *can* make sense to mention the name of an entry without the
task-name-dot prefix, at least in some unusual cases:
task trace is
entry put(str : string) ;
end trace ;
task body trace is
task Nested;
task body Nested is
begin
Put("Hello, world."); -- No deadlock here.
end Nested;
begin
accept Put (str : string) do
declare
Y: String := Put.Str; -- No deadlock here.
begin
...
end;
end Put:
end Trace;
- Bob
--
Change robert to bob to get my real email address. Sorry.
prev parent reply other threads:[~1998-12-23 0:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-12-15 0:00 "recursive" accept statement ?? Frederic Voisin
1998-12-15 0:00 ` Marc A. Criley
1998-12-15 0:00 ` Matthew Heaney
1998-12-15 0:00 ` dennison
1998-12-15 0:00 ` Matthew Heaney
1998-12-15 0:00 ` Tucker Taft
1998-12-15 0:00 ` David C. Hoos
1998-12-23 0:00 ` Robert A Duff [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox