Ruben
Ruben

Reputation: 304

Declaring variables in in Fortran

Why does this piece of code not work and what is the alternative?

module find_integers_module  
  implicit none
  contains  
  integer function function1(r) result(rnext)   
    implicit none   
    integer,intent(in) :: r     
    integer :: k = r    
    rnext = -1          
  end function function1     
end module

Upvotes: 0

Views: 98

Answers (1)

High Performance Mark
High Performance Mark

Reputation: 78316

The Fortran standard requires that the rhs of the initialisation in integer :: k = r be a constant-expression; you might care to think of that as computable at compile-time though that's not how the standard puts it.

The workaround is simple:

integer :: k
k = r

Upvotes: 4

Related Questions