Fortran assignment on declaration and SAVE attribute gotcha

I don’t think that there is some rationale behind such behavior.

But as far as I know, Stefano, you used wrong terminology. In your code there is no assignment statement only variable (var) initialization using initialization expression (0).

integer :: var = 0 ! type declaration & initialization

integer :: var ! type declaration
var = 0        ! assignment

So it seems that it was just committee design decision. If we have such expression (with equality sign in type declaration statement) it is initialization not assignment. And initialization takes place only once during program (and not procedures) execution.

However there might be some historical reasons for such decision. Take a look at this thread.

Today such behavior is dangerous because many other widely used languages follows another conventions about initialization/assignment.

Leave a Comment