Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Comunicados
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Silent truncation of character parameters

Harald
Principiante
1.031 Visualizações

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.

Sample code:

! 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

This prints:

 

% ifort -V 
Intel(R) Fortran Compiler XE for applications running on IA-32, Version 15.0.5.223 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.

 

0 Kudos
2 Respostas
Steven_L_Intel1
Funcionário
1.031 Visualizações

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.

Steven_L_Intel1
Funcionário
1.031 Visualizações

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.

Responder