Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Silent truncation of character parameters

$
0
0

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.

 


Viewing all articles
Browse latest Browse all 3270

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>