RFC legacy support for array constructor with different string lengths
Daniel Kraft
d@domob.eu
Tue Sep 2 09:31:00 GMT 2008
Tobias Burnus wrote:
> 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?
For reference: http://gcc.gnu.org/ml/fortran/2008-05/msg00216.html
I guess this was 'introduced' with my patch there for PR 36112.
And in http://gcc.gnu.org/ml/fortran/2008-05/msg00218.html, FX is
clearly of the opinion to reject such code. I think it depends on how
common code like that is. If there seems not to be too much of a
problem with legacy code, I'd keep the behaviour we have now. If there
is and you determine to allow such code, I'll implement this into my
bounds-checking fix.
Cheers,
Daniel
--
Done: Arc-Bar-Cav-Sam-Val-Wiz, Dwa-Elf-Gno-Hum-Orc, Law-Neu-Cha, Fem-Mal
To go: Hea-Kni-Mon-Pri-Ran-Rog-Tou
More information about the Fortran
mailing list