f2003/f2008, class/extends, multiple gemeric assignment
Paul Kapinos
kapinos@rz.rwth-aachen.de
Tue Jan 7 19:03:00 GMT 2014
Dear Fortran gurus,
please take a look at the attached example. It cannot be compiled using the
gfortran/4.8.1:
> $ gfortran -c ___MOD_paul.f90
> ___MOD_paul.f90:42.42:
>
> generic :: assignment(=) => assign2
> 1
> Error: 'ass_gf' and 'ass_en' for GENERIC '=' at (1) are ambiguous
Actually this code piece is derived from an real world code which is developed
using Intel compiler (may be compiled with ifort, runs OK) and the actual
prevents from porting the code (being still in development) to 'gfortran'.
Well, let's take a look at the code.
- module 'kleiner' is no problem - can be compiled when in own file. Type
'mytype' is defined and '=' is bound to this type.
- module 'grosser' is meant to be a subclass of 'kleiner': the type 'zwotype'
extends the type 'mytype'. Again '=' should be bound to the new (derived) type
'zwotype' - and this fals.
Well, as said the Intel's "ifort" compile this with no warnings and AFAIK the
code also runs well. The question now is:
- is that some Intel's extension, or
- is that an Fortran 2003/2008 feature still not supported in gfortran, or
- is the code in any way not Fortran-standard complying?
It would be quite vital for our user to know what is the root of the evil in
order to decide what to do with the code now. (as said the example is derived
from a bigger an fairly complicated code).
Best from Aachen
Paul Kapinos
P.S. Note that 'ass_gf' and 'ass_en' have *different* signatures:
> subroutine ass_en(result,incoming)
> class (mytype), intent (out) :: result
> class (*), intent (in) :: incoming
> subroutine ass_gf(result,incoming)
> class (zwotype), intent (out) :: result
> class (*), intent (in) :: incoming
whereby, yes, 'zwotype' is derived from (but not equal to!) 'mytype'
--
Dipl.-Inform. Paul Kapinos - High Performance Computing,
RWTH Aachen University, Center for Computing and Communication
Seffenter Weg 23, D 52074 Aachen (Germany)
Tel: +49 241/80-24915
-------------- next part --------------
module kleiner
implicit none
type mytype
real,private :: meane = 0.0
contains
generic, public :: assignment(=) => assign
procedure, private :: assign => ass_en
end type mytype
contains
subroutine ass_en(result,incoming)
implicit none
class (mytype), intent (out) :: result
class (*), intent (in) :: incoming
select type (incoming)
type is (mytype)
result%meane = 1.0
type is (real)
result%meane = incoming
class default
write(*,*) 'Type mismatch in type mytype'; stop
end select
end subroutine ass_en
end module kleiner
!------------------------------------------------------------------------------!
module grosser
use kleiner, only: mytype
implicit none
type, extends(mytype) :: zwotype
real,private :: flux_
contains
generic :: assignment(=) => assign2
procedure, private :: assign2 => ass_gf
end type zwotype
contains
subroutine ass_gf(result,incoming)
implicit none
class (zwotype), intent (out) :: result
class (*), intent (in) :: incoming
select type (incoming)
type is (mytype)
type is (zwotype)
result%flux_ = 42.0
type is (real)
class default
write(*,*) 'Type mismatch in type zwotype'
stop
end select
end subroutine ass_gf
end module grosser
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4533 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20140107/d7133963/attachment.p7s>
More information about the Fortran
mailing list