Kenneth_Smith
Joined: 18 May 2012 Posts: 759 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Thu Jan 09, 2025 3:22 am Post subject: error 474 - Invalid expression in array constructor |
|
|
I think the error reported by the compiler in this case is not correct.
I don't understand how an implied do loop / array constructor can reference an intrinsic function, but not a function defined elsewhere in the code.
Any ideas/explanations welcome.
Ken
Code: | module demo_problem2
implicit none
contains
elemental function squareD (x) result (returnval)
real*8, intent(in) :: x
real*8 :: returnval
returnval = x*x
end function squareD
end module demo_problem2
program p2
use demo_problem2
implicit none
integer, parameter :: n = 5
integer :: i
real*8 :: a(n)
! forall (i = 1:n:1) ! This works with FTN95, for elemental squareD
! a(i) = squareD(dble(i))
! end forall
! do i = 1, n ! This works with FTN95
! a(i) = squareD(dble(i))
! end do
! a = [(sin(dble(i)),i=1,n,1)] ! This works with FTN95 - when referencing an intrinsic function
a = [(squareD(dble(i)),i=1,n,1)] ! This does not work with FTN95 - when referencing an non-intrinsic function
! error 474 - Invalid expression in array constructor
do i = 1, size(a)
print*, i, a(i)
end do
end program p2 |
|
|