I have a function that looks like this:
PURE FUNCTION simulate(initial_state, time_specification)
TYPE(ocean), INTENT(IN) :: initial_state
TYPE(simulation_time), INTENT(IN) :: time_specification
TYPE(ocean) :: simulate
REAL :: t = 0.0
! etc
END FUNCTION simulate
gfortran 4.8.1 informs me that
REAL :: t = 0.0
1
Error: Initialization of variable at (1) is not allowed in a PURE procedure
As I understand it, I should be able to use local variables within pure functions as long as they do not have the SAVE attribute. So what am I doing wrong?
Fortran variables are NOT by default initialized to anything. I believe C++ is the same. See -finit-real .
Local Variables. Local variables must be initialized before use, as they don't have a default value and the compiler won't let us use an uninitialized value.
Under modern Fortran initialization implies SAVE
. From F2008 5.2.3
Explicit initialization of a variable that is not in a common block implies the SAVE attribute, which may be confirmed by explicit specification.
You can use local variables, but just
real t
t = 0
which isn't initialization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With