- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Consider the following 64-bit program:
program foo
implicit none
real, allocatable :: array(:)
integer(8) :: i
i = Z'0000000100000000' + 5_8
allocate(array(i)) ! 2^32 + 5
print *,ubound(array), ubound(array,1,kind(i))
end program foo
Output:
5 4294967301
It is easy (for me) to overlook that the IVF language states:
The result type is integer. If kind is present, the kind parameter of the result is that specified by kind
Therefore, in 64-bit programs care must be taken with arrays who's bounds exceed those of default integer (integer(4)).
This can introduce a programming error "Sight seen but unseen"
Jim Dempsey
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This applies to many intrinsics, and is exactly why the KIND argument was added to many of them.
I'll also comment that the assignment to i is non-standard, and the results implementation-dependent. Even in Fortran 202x, which expands the use of BOZ constants, this would not be allowed. See Doctor Fortran in "We're All BOZos on This Bus" - Doctor Fortran (stevelionel.com) for more information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>I'll also comment that the assignment to i is non-standard
I found that out
The compiler balked at:
i = Z'0000000100000000' + 5 ! sans _8
FWIW would this be preferred?
i = INT(Z'0000000100000000', kind(i)) + 5
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That would be fine.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page