comp.lang.ada
 help / color / mirror / Atom feed
From: Philip Anderson <phil.anderson@amsjv.com>
Subject: Re: Calling through function pointer--syntax question
Date: Mon, 11 Jun 2001 14:08:17 +0100
Date: 2001-06-11T14:08:17+01:00	[thread overview]
Message-ID: <3B24C2C1.CC3C4382@amsjv.com> (raw)
In-Reply-To: x7vwv6mjhcw.fsf@smaug.pushface.org

Simon Wright wrote:
> 
> This has to be the second P. If you were meaning to call the first P,
> you would write

Would or must?
 
>     P (func.all (5));
> 
>   with Ada.Text_Io; use Ada.Text_Io;
>   Procedure Q is
>     type Func_Ptr is access function (Param : Integer) return Integer;
>     function Actual (Param : Integer) return Integer is
>     begin
>       return 0;
>     end Actual;
>     function Func (Y : Integer := 4) return Func_Ptr is
>     begin
>       return Actual'Access;
>     end Func;
>     procedure P (X : in Integer) is
>     begin
>       Put_Line ("first interpretation");
>     end P;
>     procedure P (X : in Func_Ptr) is
>    begin
>       Put_Line ("second interpretation");
>     end P;
>   begin
>     P (Func (5));
>     P (Func.all (5));
>   end Q;
> 
> results in
> 
>   second interpretation
>   first interpretation
> 
> (GNAT 3.14a)

Using Rational Apex for NT 3.0.2b, this gives an error:

*** Unit has semantic errors
P could be (in Q) P
P could be (in Q) P
P (Func (5)); is an ambiguous call

Commenting out the second P, it compiles quite happily, resulting in

first interpretation
first interpretation


Likewise, using named parameter association to disambiguate calls

P (Func (Param => 5));
P (Func (Y => 5));
P (Func.all (5));

which is accepted, and results in

first interpretation
second interpretation
first interpretation


So I think Adam does have a case.  Also, either Rational or Gnat appears
to have a bug.


-- 
hwyl/cheers,
Philip Anderson
Alenia Marconi Systems
Cwmbr�n, Cymru/Wales



  reply	other threads:[~2001-06-11 13:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-05 17:43 Calling through function pointer--syntax question adam
2001-06-05 19:39 ` tmoran
2001-06-06 16:17   ` Adam Beneschan
2001-06-06 16:00 ` Tucker Taft
2001-06-06 22:06   ` Adam Beneschan
2001-06-07  1:22     ` Jeffrey Carter
2001-06-08 21:34       ` Adam Beneschan
2001-06-09  6:29         ` Simon Wright
2001-06-11 13:08           ` Philip Anderson [this message]
2001-06-11 17:34         ` Tucker Taft
replies disabled

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