[J3] Consistency in conversion functions

Ondřej Čertík ondrej at certik.us
Wed Apr 5 05:02:40 UTC 2023

Hi Jeff,

On Tue, Apr 4, 2023, at 1:52 AM, Jeff Hammond via J3 wrote:
> To convert INTEGER kinds, we use INT().
> To convert COMPLEX kinds, we use CMPLX().
> To convert REAL kinds, we use REAL().
> To convert LOGICAL kinds, we use LOGICAL().
> Does this bother anyone else?

It bothers me too, and I think this is a good proposal, so I created an issue for it: https://github.com/j3-fortran/fortran_proposals/issues/295, go ahead and give it +1 if you like it.

In fact to this day I don't remember the difference between cmplx and complex and the `(x,y)` syntax, and another inconsistency (for me) is that real(z) will cast to a single precision if "z" is double precision real, but it will keep double precision if "z" is double precision complex. So in my code, if I write real(z), and then change "z" from complex to real, because "z" happens to be real in some case, I get single precision, which is not what I want.

Unfortunately Fortran has many such warts, that every single newcomer hits (such as implicit typing, implied save, single/double precision mistakes, etc.). I personally think they should all be fixed (while keeping backwards compatibility). The committee and community is split on this, I personally know many both at the committee and outside of it who agree with me and many who do not agree. There are good arguments on both sides, and I tried to summarize both sides in the issue above.

Fortunately almost all of these can be fixed in a compiler. So it's good to have more compilers with different defaults and users can choose. I encourage you to get support for your proposal at the vendor you work for. I still think most (if not all) changes should be lead by compilers and users, and the committee should only standardize already "common practice".


More information about the J3 mailing list