[log in to unmask] writes:
> A problem I have had more than once, but most recently using xlf:
> The following statement
> IF (K.GT.0 .AND. X(K).GT.0.) THEN
> produces an error condition when K=0 and X is dimensioned in a normal way,
> i.e., 0 is an invalid subscript for X.
>
> My question is whether this behavior is a violation of the FORTRAN standard.
Your code is illegal. The Fortran standard is very explicit about
this. I think it even has an example almost like that, though I'm too
busy to drag it out and analyze the simillarities at the moment. The
standard (all versions) is quite explicit that expressions like the
above can be evaluated in any order, and the compiler may or may not
choose to skip evaluation of some parts.
Your code is assuming that the compiler first evaluates the K.GT.0
part and then skips the evaluation of X(K).GT.0. if the first part
evaluated to false. A compiler is *ALLOWED* to operate like this, but
is certainly not *REQUIRED* to. Conversely, if your code depends on
this behavior (and the above code does), then it is illegal.
The compiler could very well evaluate X(K).GT.0 first, before looking
at the K.GT.0 part. Or it could evaluate both parts in parallel on
suitable hardware. Or it could evaluate K.GT.0 and then
unconditionally evaluate X(K).GT.0.
--
Richard Maine
[log in to unmask]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|