Lorents <
aq...@ehjs.com> wrote:
...
> character(len=wl), parameter :: CLASSNAMES(1:Nobjects) =
> (/"Cat","Rhino","Dolphin"/)
...
> but when I specify '-stand f95' (check conformance to Fortran 95) I get
> the following warning:
>
> warning #8208: If type specification is omitted, each ac-value
> expression in the array constructor of type CHARACTER must have the
> same length type parameters.
>
> In fact adding spaces at the end of the string so that they all have the
> same length (e.g. "Cat ") gets rid of the warning; is there anything
> I can do to avoid the warning without having to do this padding by hand
> for all strings?
Not in f95. Yes, I agree it's a pain. But as of f2003...
> Besides, why the error message says 'If type specification is omitted'?
> Am I not specifying that the array is of type character?
That's referring to a feature of array constructors new to f2003. It is
a type specification as part of the array constructor syntax. Yes, you
have a type specifier for the array, but remember (or become informed,
as the case may be) that Fortran expressions have meaning independent of
context. In particular, the array constructor
(/"Cat","Rhino","Dolphin"/)
gets evaluated *WITHOUT* looking anywhere else in the statement for how
to interpret it. It has to stand on its own. And on its own, there is no
way to tell what character length you intended. There were a bunch of
attempts to make this sort of thing "just work", but every one of them
had problems with various esoteric cases. Your particular case isn't
esoteric, but a rule in the standard has to work for all cases.
This necessity for explicit blank padding in character array
constructors happens to be the first official interpretation question I
ever asked about Fortran, back circa 1990 before I was on the committee.
Hmm. Come to think of it, I think I posted the question here, but a
committee member took my posting and turned it into an official interp
request.
A way around it, as of f2003, is to put a type specification inside of
the array constructor. Yes, I know it looks redundant. But it does make
things work for *ALL* cases. Change the constructor to
[character(len=w):: "Cat", "Rhino", "Dolphin"]
Well, if you prefer, you can keep the (/../) delimitters instead of the
[..], but I strongly prefer the square brackets, so I wrote it that way.
That's also new to f2003.
--
Richard Maine
email: last name at domain . net
dimnain: summer-triangle