I didn't know I could add an integer to an array. Is there a compiler option that prevents this?

Let integer dimension(6) :: f

Consider this statement: f = f + 1

I just now realized that my compiler will accept this statement. I’ve been using fortran for years, and it never occurred to me that this statement would be valid. In my particular situation, I had an error in my code that I didn’t see for a month. If my compiler would have rejected the statement, I would have found the error much earlier. I wonder if there is a compiler option that would reject the above statement?

1 Like

Welcome to the forum. The basic principle is that a scalar is conformable with an array of any rank, so

integer, dimension(6,4) :: f
f = 0
f = f + 1
f = 2*f
f = f**3

is also valid. This is common and has been allowed since Fortran 90 on, and if you want to program in modern Fortran, you have to know its rules.

1 Like

Thanks for the clarification on this matter. I don’t know how I missed all this.