It should work, unless I'm missing something obvious.
"length" is a variable initialized to -1. The fact that
it is initialized implies that it has the SAVE attribute, so
it will retain it's value. Because it is above the contains
it is available for use in all of the subroutines below
the contains.
If you call setup, length will get the value 10. The variable
length is also available outside of the moudlue and could be
changed by other routines.
The array "array" is an automatic array and is "created", probably
on the stack, each time exploit is called. It goes away when
the subroutine returns. It has whatever size
"length" is set to. If length is -1 (or anything less than +1) the
array has zero size and array = ... is essentially a do nothing
statement.
Alexei Matveev wrote:
>
> Hello, Everybody,
>
> I'm in doubts -- is the following
> construction legal? I found it somewhere and
> I'm wondering why it works:
>
> module mod
>
> integer :: length = -1
>
> contains
>
> subroutine setup()
> length = 10
> end subroutine setup
>
> subroutine exploit()
> ! declarations of internal variables:
> real :: array(length)
> ! executable code:
> array = ...
> end subroutine exploit
>
> end module mod
>
> Alexei
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|