This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [4.5, Patch, Fortran] PR 36704: Procedure pointer as function result
- From: Mikael Morin <mikael dot morin at tele2 dot fr>
- To: Tobias Burnus <burnus at net-b dot de>
- Cc: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Tue, 09 Dec 2008 02:18:43 +0100
- Subject: Re: [4.5, Patch, Fortran] PR 36704: Procedure pointer as function result
- References: <20081208221557.GA28547@net-b.de>
Tobias Burnus wrote:
> Can you give an example? In most cases there exists both a specific and
> a generic version with the same name; e.g. "SIN(X)" exists as generic
> procedure for all kinds of REAL and COMPLEX; however, there exists also
> a specific function called "SIN" which takes the default-kind REAL as
> argument.
I was trying this:
!!!!!!!!!!!!!!!!!!!!!!!!
implicit none
procedure(real*8), pointer :: q
q => i()
if (q(1.d0) /= sin(1.d0)) call abort ()
contains
function i()
intrinsic sin
pointer :: i
interface
function i(x)
real(8) :: i,x
end function i
end interface
i => sin
end function
end
!!!!!!!!!!!!!!!!!!!!!!!!!
which leads to this:
----------------------------
i ()
{
real(kind=4) (*<T3bd>) (real(kind=8) &) (*<T3c1>) (real(kind=8) &) ppr@;
ppr@ = (real(kind=4) (*<T3bd>) (real(kind=8) &) (*<T3c1>)
(real(kind=8) &)) _gfortran_specific__sin_r4;
return (real(kind=4) (*<T3bd>) (real(kind=8) &)) ppr@;
}
MAIN__ ()
{
real(kind=8) (*<T3c8>) (void) q;
static integer(kind=4) options.0[8] = {68, 255, 0, 0, 0, 1, 0, 1};
static real(kind=4) (*<T3bd>) (real(kind=8) &) i (void);
_gfortran_set_options (8, (void *) &options.0);
q = (real(kind=8) (*<T3c8>) (void)) i ();
{
static real(kind=8) C.1538 = 1.0e+0;
if (q (&C.1538) !=
8.414709848078965048756572286947630345821380615234375e-1)
{
_gfortran_abort ();
}
}
}
---------------------------------
As you can see, the sin_r4 specific is called, not the sin_r8 as I expected.
But as Janus said procedure pointer interfaces are
disabled/unimplemented for now.
>
> See in the F2003 standard:
> "13.6 Specific names for standard intrinsic functions"
> "Except for AMAX0, AMIN0, MAX1, and MIN1, the result type of the specific
> function is the same as the result type of the corresponding generic
> function would be if it were invoked with the same arguments as the
> specific function."
I understand this as: The type of the result matches that of the argument
but said with a complicated and obfuscated sentence.
Too late to try to understand. I don't want to have nightmares.
> Those intrinsics marked with a bullet (*) in that list cannot be used
> as proc-pointer target (or as actual argument).
Sin is not marked with a bullet :)
Mikael