GNU Extension and intrinsics
Mark Eggleston
mark.eggleston@codethink.co.uk
Thu Jan 31 13:25:00 GMT 2019
A number of intrinsic functions have two parameters that must match by
type and kind such as "dim" and "mod". In addition there are two
intrinsics "max" and "min" that also require the parameters to match by
type and kind. The documentation for "max" and "min" at
https://gcc.gnu.org/onlinedocs/gfortran/Intrinsic-Procedures.html#Intrinsic-Procedures
states for the parameters following the first that "As a GNU extension,
arguments of different kinds are permitted."
Using -std=f95 the following error is produced:
25 |Â Â write(*,*) max(1_1, 2_4, 6_4)
  |                     1
Error: GNU Extension: Different type kinds at (1)
The same error is also produced for "dim", "mod" and "modulo" but not "sign"
e.g.:
26 |Â Â write(*,*) modulo(17, 5_2)
  |                       1
Error: GNU Extension: Different type kinds at (1)
There is no mention of the GNU extension applying to "dim", "mod" and
"modulo". The intrinsic "sign" has its parameter described in the same
way as mod so should the GNU Extension also apply to sign?
According to the standard (N692 Fortran 90) the type and kind of the
return parameter should match that of the first parameter. The GNU
Extension is not standard, for dim, mod and modulo the kind of the
return type is the higher of the two parameters so the return type for
mod(33_2, 5_4) is integer(4) instead of integer(2).
Comparing with PGI Fortran: its the return type for mod(33_2, 5_4) is
integer(2). Oddly PGI Fortran returns integer(4) for mod(67_1, 4_1). PGI
Fortran also accepts different types: mod(67_2, 4.0) will
return an integer(2).
Should the GNU Extension apply to sign?
The documentation should be updated to reflect where the GNU Extension
applies.
Should the return type always match the type of the first parameter?
Would it be reasonable to modify the GNU Extension to allow for
different types (integer or real) as well as different kinds?
Mark
--
https://www.codethink.co.uk/privacy.html
More information about the Fortran
mailing list