NAG also uses a -kind=unique flag which guarantees that no two KIND numbers are the same, precisely to catch errors where an INTEGER KIND number is use for a REAL KIND.
Nice. Does it have a “Here’s your sign” message for code like
program showit
implicit none
write(*,*)10_2, 29_4,100_8,10.0_4,10.0_8
end program showit
Can we at least ban direct use of numeric kind type parameters?
character mnemonics are much better and can be changed with a single line, whereas direct use of numbers is not necessarily portable and not the most intelligible. I think the kind values should be randomly generated for each compilation to discourage their use:
One obstacle with this is that almost every compiler documents its intrinsic functions by using literal kind values. Beginners to fortran see this documentation and take it as an informal guide to the way fortran code should be written, not fully understanding that extra level of abstraction that they should be using.
And then there are the experienced fortran programmers that think real*8 and real(8) should mean the same thing. So using parameter values gets short circuited going and coming.
Now that we have the iso_fortran_env variables, it seems like the first problem could be solved if compiler documentation would at least use those parameters rather than literal integers. Further, as in the NAG compiler, that also makes the code independent of whichever of the three kind conventions is specified by compiler options.
Regarding byte values in general, the problem is that there can be multiple floating point formats supported that have the same numbers of bytes. VAX fortran had this feature back in the 1980s for 64-bit floating point, but that architecture did not survive to see f90 compilers. But now we see hardware that supports two different 16-bit formats and two different 32-bit formats. There is also now binary and decimal floating point formats that share the same byte size. This should be an ideal situation for the fortran language with its kind abstraction, but for some reasons that I do not understand, fortran compilers are lagging behind other languages in supporting those formats.