There appears to be a silent truncation of character parameters under certain circumstances. This may be related to some internal limit. However, I do not get any warning for this truncation.
! Silent truncation of character parameters ! integer, parameter :: huge_2 = 7197_2 ! still ok with 7196 integer, parameter :: huge_2 = huge(0_2) character( huge_2 ), parameter :: u = 'abc' character( huge(0_2) ), parameter :: v = 'abc' character(int(huge(0_2),4)), parameter :: w = 'abcdef' character( huge(0_2) ) :: b = 'abc' integer, parameter :: huge_1 = huge(0_1) character( huge_1 ), parameter :: x = 'abc' character( huge(0_1) ), parameter :: y = 'abc' character( huge(0_1)+0 ), parameter :: z = 'abcdef' character( huge(0_1) ) :: a = 'abc' print*, huge_2, len(u), len(v), len(w), len (b) print*, huge_1, len(x), len(y), len(z), len (a) end
% ifort -V Intel(R) Fortran Compiler XE for applications running on IA-32, Version 188.8.131.52 Build 20150805 % ./a.out 32767 3 3 6 32767 127 127 127 127 127
I'd expected 32767 for all columns of the first line. There appears to be a limit as indicated in the above code sample.
I'm not going to argue that the above code is very useful, but it might be helpful to generate some warning for the user.
Very interesting. While there is a documented limit on the length of a character constant (7198), the compiler is definitely doing something wrong here. It's also interesting that the bad results start at length 7197. I will let the developers know - thanks for the nice test case. Issue ID DPD200408829.
This will be fixed for the 17.0 release. You'll now get a compile-time error if a character constant (including PARAMETER) exceeds 7198 characters, and the odd behavior for 7197 characters will go away.