Le 28/01/2024 à 09:54, Thomas Koenig a écrit :
> Lawrence D'Oliveiro <***@nz.invalid> schrieb:
>> On Sat, 27 Jan 2024 22:58:27 -0000 (UTC), Thomas Koenig wrote:
>>
>>> Lawrence D'Oliveiro <***@nz.invalid> schrieb:
>>>
>>>> It even does recursive functions/subroutines. But you must explicitly
>>>> declare them RECURSIVE, which C doesn’t.
>>>
>>> It's the functionality that counts, not the syntax.
>>
>> You shouldn’t need separate syntax to enable something that should be
>> available as a matter of course.
>
> What "should be available as a matter of course" is very much
> an opinion, and there are two sides to that argument what should
> be the default.
>
> Just one example: Stack sizes are severely limited even on modern
> systems, at least by default (and sometimes even more severely
> for multithreaded applications). So, it is quite possible for an
> application to work fine with non-recursive subroutines, but to
> crash mysteriously with recursive subrotines, on modern systems.
I am a bit puzzled by such a debate.
First of all I don't get why the OS's define such small stack sizes by
default, given the amounts of RAM that are available on current hardware.
Second, it's up to the compilers to follow appropriate allocation
strategies, and I must say that both gfortran and Intel Fortran have IMHO
weird strategies:
- above a given size, gfortran reverts from stack allocation to static
memory (*)
- by default, Intel Fortran sticks to stack allocation for automatic
variables/arrays and for temporary arrays, without bothering at all to
check the stack size
I would expect compilers to allocate small objects on the stack, and
larger objects on the heap.
(*) by the way, it's still unclear to me what happens in gfortran with
large automatic arrays when the size is not known at compile time?
Third, every programmer should be aware that large automatic objects are
not a good idea given the usually limited stack sizes.
And last, the main reason to get away from static variables in the
routines is multithreading, much before recursion.
> So, should a compiler by default follow F2018 (which makes
> procedures recursive by default) or not? Hmmm...
Of course it should. Adherence to the standard ensures portability.