[J3] Question involving explicit initialization

Bill Long longb at cray.com
Sat May 4 11:00:07 EDT 2019

> On May 4, 2019, at 9:46 AM, Vipul Parekh via J3 <j3 at mailman.j3-fortran.org> wrote:
> Does the following code conform to the Fortran standard?

Yes.  I don’t see any cause for doubt.

In each subroutine the variable i is local. Initialization causes it to have the SAVE attribute.  Since there is no method for the value of i to be exposed outside the subroutine, I don’t see any value to incrementing it. But there are lots of examples of pointless codes that are standard conforming.   If i did not have the SAVE attribute, almost certainly the compiler would not generate code for the increment or allocate storage for i. 

It is reassuring that none of the compilers generated a message for this code. 


> --- begin code ---
> module m
> contains
>   subroutine sub1()
>      integer :: i = 0
>      i = i + 1
>   end subroutine
>   subroutine sub2()
>      integer :: i = 0
>      i = i + 1
>   end subroutine
> end module
> --- end code ---
> None of the compilers I tried raise any errors with above.
> Thanks and regards,
> Vipul Parekh

Bill Long                                                                       longb at cray.com
Principal Engineer, Fortran Technical Support &   voice:  651-605-9024
Bioinformatics Software Development                      fax:  651-605-9143
Cray Inc./ 2131 Lindau Lane/  Suite 1000/  Bloomington, MN  55425

More information about the J3 mailing list