[J3] Default values for optional arguments

Bill Long longb at cray.com
Thu Jan 21 03:55:03 UTC 2021


OPTIONAL and VALUE cannot be specified together for a dummy argument in a  procedure with the BIND attribute. 

Cheers,
Bill

> On Jan 20, 2021, at 8:50 PM, William Clodius via J3 <j3 at mailman.j3-fortran.org> wrote:
> 
> To me there are two possible argument passing attributes for default arguments: INTENT(IN) or VALUE. INTENT(IN) arguments cannot have the ALLOCATABLE attribute and with the absent argument the default would be a constant in the environment of the call site and the argument passing . With the VALUE attribute an absent argument with a default value could have the interpretation of an automatic local variable with automatic initialization.
> 
>> On Jan 20, 2021, at 3:00 PM, Van Snyder via J3 <j3 at mailman.j3-fortran.org> wrote:
>> 
>> On Wed, 2021-01-20 at 12:28 +0000, Bill Long via J3 wrote:
>>> There was a proposal for default optional argument values for F202X that failed for the reason given above.   Something like
>>> 
>>> integer, intent(in), optional, default(42) :: b
>>> 
>>> might work.If this were to work, then subsequent tests for Present(b) would have to return true to avoid conflicts with existing code. There might be other side effects that are undesirable. 
>> 
>> It's not obvious how this would work if the optional argument is an allocatable array.
>> 
>> The obvious interpretation of an absent optional argument with a default value is that it becomes an automatic local variable, with automatic initialization.
>> 
>> People have been asking for automatic initialization, i.e., that doesn't imply SAVE, for decades.
>> 
> 

Bill Long                                                                       longb at hpe.com
Engineer/Master , Fortran Technical Support &   voice:  651-605-9024
Bioinformatics Software Development                      fax:  651-605-9143
Hewlett Packard Enterprise/ 2131 Lindau Lane/  Suite 1000/  Bloomington, MN  55425






More information about the J3 mailing list