RFC legacy support for array constructor with different string lengths

Tobias Burnus burnus@net-b.de
Tue Sep 2 08:55:00 GMT 2008


Hi,

when reading 
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/75fa01278753793e 
, I saw that

  character(len=14), dimension(5), parameter :: var_names &
    & = ['YEAR', 'COMPCODE', 'RECEPTYPE', 'NCOLS', 'NROWS']

is now rejected with gfortran 4.4:

Error: Different CHARACTER lengths (4/8) in array constructor at (1)

With gfortran 4.2 and 4.3 it is accepted by default (with no warning with -Wall/-pedantic) but rejected with -std=f2003.


The proper solution is to use Fortran 2003's

  character(len=14), dimension(5), parameter :: &
       var_names = [character(len=14) :: &
       'YEAR', 'COMPCODE', 'RECEPTYPE', 'NCOLS', 'NROWS']

or for Fortran 90/95: To pad the strings manually to equal length (and to use (/ ... /) instead of [...]).

 * * *

Question: Some other compilers, e.g. ifort and openf95, allow the first example with default option, with -stand f03 ifort print a warning. Does it make sense to think about supporting it as legacy extension (e.g. combined with printing a default warning)? Or should one simply reject it - as NAG f95, g95 and sunf95 do?

I'm not sure what is the better solution. (Maybe keep the status quo, especially since it is less work ;-)

Tobias



More information about the Fortran mailing list