Lawrence D'Oliveiro <l...@nz.invalid> schrieb:
> On Sun, 28 Jan 2024 16:41:21 -0000 (UTC), Steven G. Kargl wrote:
>
>> I submitted a patch to implement the NON_RECURSIVE prefix and made the
>> change to make procedure recursive by default. It's in bugzilla. Janne
>> and I had a short discussion, and we are both leary of what might happen
>> with the stack; particular for an OS that provides a small stack.
>
> Large objects tend to be variable in size anyway; how do you deal with
> that?
In a recent Fortran, a programmer can use
- Pointers The memory management is then done with ALLOCATE
and DEALLOCATE, much like C's malloc()/calloc() and free().
Known to be error-prone
- Allocatable variables. Allocating is done by the programmer,
deallocation can be done either manually or when the variable
goes out of scope. This can be somewhat tricky for compilers
to get right, but the burden is on the compiler writers,
where it belongs, and not on the programmers :-)
- An explicit shape with non-constant bounds, such as
subroutine foo(n)
integer :: n
real, dimension(n,n) :: a
Since Fortran 2008, this is also possible with BLOCK constructs.
This is similar to alloca() (a non-standard C construct) or
to VLAs in C.
The compiler is then responsible for handling the memory allocation
in a meaningful way - it can either allocate the memory on the
stack or on the heap.
>Do you stop and restart the program with a different global
> allocation size?
What people did in Fortran 77 and prior was usually to have a
global COMMON block which was then parcelled out piecewise.
Ugly, error-prone and no longer needed these days.
If you look at LAPACK intefaces, you still see lots of arguments
which are relatd to original and actual size of arrays - not pretty.
I wish they would use more modern features.
> In modern languages, we do most dynamic allocations, especially large
> ones, in the heap.
Assume you have a fixed-size buffer for some sort of blocked
algorithm. Where do you put it? If you make your subroutine
recursive, where it wasn't before, you suddenly end up using
a lot more stack, which then can crash a user's program.
And changing the default would cause that crash without source
code modification... which is bad.