Re: Strange Porting Problem CVF to IVF, requesting help and ideas.
Richard E Maine wrote:
> In particular, LOC returns an integer. I might add that it is an integer
> of default size, although early standard Fortran only acknowledged a
> single size of integer (and only a single size was available on some
> important architectures, speaking of architectural neutrality).
On the compilers that I am familiar with, LOC returns a 64-bit integer
when the code is compiled for a 64-bit memory model. The problem is
that the result gets silently 'narrowed' when fed into a default-sized
integer. As you say:
> .... An example from today is so-called 64-bit systems, where
> addresses take 64 bits, but default Fortran integers are still 32 bits.
Yup. And a number of the Fortran intrinsic functions are broken because
of this. Things like SIZE, UBOUND, LBOUND, LEN, LEN_TRIM, INDEX, and
so on. Code silently breaks as arrays and character strings, grow past
2gig. It is really a bad problem.
F2003 tried to patch around some of this by allowing a KIND arg on the
intrinsics. But I think this was a poor symptomatic fix at best.
IMO, the Standard should have a KIND available, perhaps residing in
ISO_FORTRAN_ENV, which represents an integer capable of holding the
SIZE of the largest array the implementation supports. (Kinda like
size_t in C.) Same for character string length. Then the intrinsics
should be defined to return results in terms of these types/kinds.
There would be no compatibility issues that I can see. Just programs
that used to be broken would suddenly start working...