[Bug fortran/97272] Wrong answer from MAXLOC with character arg

anlauf at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Oct 5 07:16:38 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272

--- Comment #6 from anlauf at gcc dot gnu.org ---
(In reply to Bill Long from comment #5)
> The original intent of adding the KIND argument was because some
> implementations used a 32-bit integer for the result, and it is possible for
> the answer to be larger than 2**31-1.  Just checking to be sure that the
> underlying library code returns a 64-bit integer that can later be converted
> based on the KIND value.

Did you try?  It's not exactly fast, but

program test
  implicit none
  integer(8) :: k, l = 10 + 2_8**32
  character, allocatable :: a(:)
  allocate (a(l))
  print *, l
  a(:) = 'a'
  l = l - 1
  a(l) = 'b'
  print *, l
  print *, size (a, kind=8)
  k = maxloc (a, dim=1, kind=8, back=.true.)
 print *, 'k = ', k, 'a(k) = ', a(k)
end

works for me on master now on a 64-bit platform:

           4294967306
           4294967305
           4294967306
 k =            4294967305 a(k) = b


More information about the Gcc-bugs mailing list