Fortran function remembers values (newbie help)

@Colorizer indeed, this is a classic “gotcha” that every Fortran programmer encounters: Gotchas — Fortran90 1.0 documentation, and I think it’s time to fix it.

Thanks @Beliavsky for checking LFortran. Indeed, it is a “bug” in LFortran that it actually works as expected. But I am happy that it can actually compile it, we made huge progress lately.

@jacobwilliams will be pleased that we will have to “fix” this “bug” and actually introduce the save attribute.

Or do we?

What would you like LFortran to do?

I have a feeling, as noted by others before, that when any Fortran code actually has integer :: i=0, it is a bug in the code, it was not meant to add the save attribute.

I would like the default mode in LFortran to be the “strict” mode: Create pedantic/strict mode (#450) · Issues · lfortran / lfortran · GitLab, in there it’s already specified that “implied save” (the issue above) would not be allowed. So it would just refuse to compile it, with a very helpful error message how to fix it.

4 Likes