> How is CONTAINS supposed to work legally. There is no full explanation
> in my help or manuals.
I've used it for years. I think we use the same compiler. :-)
> If I have the situation where SUBROUTINE A calls SUBROUTINE B, and
> SUBROUTINE B calls subs C and D, since CONTAINS cannot be nested , can I
> write:
Right, CONTAINS cannot be nested.
> SUBROUTINE A
>
> CALL B
>
> CONTAINS
>
> SUBROUTINE B
> CALL C
> CALL C
> CALL D
> END SUBROUTINE
> SUBROUTINE C
> END SUBROUTINE
> SUBROUTINE D
> END SUBROUTINE
> END
This looks OK on the face of it. (I recommend putting the names of the
subroutines in the END SUBROUTINE statement, though.)
> Before I contact the vendor, I would like to know the legality of this
> sequence. It compiles but gives me incorrect results.
Does it compile without even a warning when all the compiler options are
set to produce strict warnings? As to the results, you probably need to
post a more complete example.
> I also found that if C and D were functions I would get a compilation
> warning that one of them had been completely wiped out by the compiler.
Do you mean "optimised away"?
> A debug session shows me that it enters routine C, but seems not to have
> inherited variables from B. Therefore, a secondary question, should all
> contained routines only inherit from A, or if called from B do they
> inherit B's variables too? I get a compilation warning that a variable
> that I assumed was inherited from B in C is used before a value is set.
> B always sets the variable before the call.
No, just from A. Calling C from B is the same as if these were both
external subroutines. (If C inherited from B, this would be "implicit
nesting".)
> These warnings tend to give me the impression that CONTAINS can only go
> down one level unless the compiler totally in-lines the code.
I don't follow this. It cannot be nested, as you said.
> My compiler inlines B into A and also declares that it has in-lined D
> into A, but no mention of C, wherein lies my failures.
Do you see a difference between compiling with and without optimisation?
|