zmth said:
Then again I ask the same question to the logic as to why that is necessary and if anyone has the same problem of not getting the correct final result of 6 or error on any other compiler other than gfortran
Everything is very logical.
By default, the subroutine parameters are passed by reference.
So, when you have declared your subroutine as
rr(j,k) and call it with variables as parameters, i.e.
call rr(m,n), then the argument
k refers to the variable
n and you can modify it.
But when you call the subroutine with constants as parameters, i.e.
call rr(1,1), then
k refers to the constant
1. Constants could not be modified - so if you try it, you will get an error.
But also if you would use the variables as subroutine parameters, using subroutine arguments for temporary computation would be very bad practice. What should be the purpose ?
You are still asking about any other compiler than gfortran...
Currently, I have only gfortran. IMO it's very good standard fortran compiler and I doubt that any other compiler behave in this case otherwise.
But you can try any other compiler self:
There is other good free compiler I used some years ago:
g95.
Then, there are some commercial compilers - one of the best shoud be
intel fortran compiler
You can try them and post here an information, if they behave in this case otherwise than gfortran.