Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Generic type-bound procedure

19 views
Skip to first unread message

James Van Buskirk

unread,
Jan 18, 2011, 2:51:43 PM1/18/11
to
I have a couple of examples that work with generic procedures:

C:\gfortran\clf\opengl3>type generic1.f90
module mytypes
implicit none
interface gen
function f(x)
real f, x
end function f
function g(x)
integer g, x
end function g
end interface
pointer(f1,f)
pointer(g1,g)
end module mytypes

module funcs
implicit none
contains
function f(x)
real f, x
f = 3*x
end function f
function g(x)
integer g, x
g = 3*x
end function g
end module funcs

program test
use mytypes
use funcs, f2=>f, g2=>g
implicit none

f1 = LOC(f2)
g1 = LOC(g2)
write(*,*) gen(1)
write(*,*) gen(1.0)
end program test

C:\gfortran\clf\opengl3>gfortran -fcray-pointer generic1.f90 -ogeneric1

C:\gfortran\clf\opengl3>generic1
3
3.0000000

C:\gfortran\clf\opengl3>type generic3.f90
module mytypes
implicit none
abstract interface
function f(x)
real f, x
end function f
function g(x)
integer g, x
end function g
end interface
procedure(f),pointer,save :: f1
procedure(g),pointer,save :: g1
interface gen
procedure f1,g1
end interface gen
end module mytypes

module funcs
implicit none
contains
function f(x)
real f, x
f = 3*x
end function f
function g(x)
integer g, x
g = 3*x
end function g
end module funcs

program test
use mytypes
use funcs, f2=>f, g2=>g
implicit none

f1 => f2
g1 => g2
write(*,*) gen(1)
write(*,*) gen(1.0)
end program test

C:\gfortran\clf\opengl3>gfortran generic3.f90 -ogeneric3
generic3.f90: In function 'test':
generic3.f90:38:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

OK, almost works. I can't tell why this is so difficult when
the same compiler accepts the code of:

http://groups.google.com/group/comp.lang.fortran/msg/dca985833b0716c7?hl=en

without complaint. Anyhow, I was hoping to extend the latter
rather inauspicious example to user-defined types:

C:\gfortran\clf\opengl3>type generic4.f90
module mytypes
implicit none
abstract interface
function f(x)
real f, x
end function f
function g(x)
integer g, x
end function g
end interface
type T
procedure(f),pointer,NOPASS :: f1
procedure(g),pointer,NOPASS :: g1
contains
GENERIC :: gen => f1, g1
end type T
end module mytypes

module funcs
implicit none
contains
function f(x)
real f, x
f = 3*x
end function f
function g(x)
integer g, x
g = 3*x
end function g
end module funcs

program test
use mytypes
use funcs, f2=>f, g2=>g
implicit none
type(T) tau

tau%f1 => f2
tau%g1 => g2
write(*,*) tau%gen(1)
write(*,*) tau%gen(1.0)
end program test

C:\gfortran\clf\opengl3>gfortran generic4.f90 -ogeneric4
generic4.f90:15.26:

GENERIC :: gen => f1, g1
1
Error: Undefined specific binding 'g1' as target of GENERIC 'gen' at (1)
generic4.f90:33.14:

use mytypes
1
Fatal Error: Can't open module file 'mytypes.mod' for reading at (1): No
such fi
le or directory
gfortran: internal compiler error: Aborted (program f951)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Pretty much syntactically the same as example3.f90, but with derived
types. If example4.f90 is nonconforming does that mean that
example3.f90 is taking advantage of an extension?

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


robert....@oracle.com

unread,
Jan 21, 2011, 7:48:36 PM1/21/11
to
On Jan 18, 11:51 am, "James Van Buskirk" <not_va...@comcast.net>
wrote:
> http://groups.google.com/group/comp.lang.fortran/msg/dca985833b0716c7...

The program in generic4.f90 is not standard conforming. Constraint
C460
on page 56 of the Fortran 2003 standard states

(R452) Each /binding-name/ in /binding-name-list/ shall be
the name of a specific binding of the type.

The names f1 and g1 in the derived type T are the names of
components of T, not the names of specific bindings. Therefore,
a processor is required to be able to produce a diagnostic
message for the generic binding given.

I know where this goes next, but I do not wish to go there now.

Bob Corbett

James Van Buskirk

unread,
Jan 21, 2011, 8:24:28 PM1/21/11
to
<robert....@oracle.com> wrote in message
news:32ce5283-4487-4e2e...@v17g2000prc.googlegroups.com...

>> Error: Undefined specific binding 'g1' as target of GENERIC 'gen' at (1)

> The program in generic4.f90 is not standard conforming. Constraint


> C460
> on page 56 of the Fortran 2003 standard states

> (R452) Each /binding-name/ in /binding-name-list/ shall be
> the name of a specific binding of the type.

> The names f1 and g1 in the derived type T are the names of
> components of T, not the names of specific bindings. Therefore,
> a processor is required to be able to produce a diagnostic
> message for the generic binding given.

> I know where this goes next, but I do not wish to go there now.

:) OK. I will not ask you why.

Thank you for your interpretation of the standard, Bob. It seems to
me that the instance where this might have come in handy might only
need procedure pointer components and not generic bindings to them
after all.

0 new messages