Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29257 Discussions

Question about usefulness of intent(in)

Andrew_Smith
Valued Contributor I
271 Views
If you specify intent(in), the Intel Fortran help file says the actual argument must be an expression. In this example where the argument is just a variable (but still a legal expession). Is the argument A evaluated as an expression and the result sent to foo to prevent modification by foo?

It seams superfluous to copy the argument when the compiler has already made sure we don't modify the dummy argument and it is illegal to attempt to do so. If A was a large data structure, making a copy would be a serious problem. Thus intent(in) would best be avoided where we are passing simple variables.

Andy

program test
use fooMod
implicit none
real A
a = 1.0
call foo(A)
end program

module fooMod
implicit none
contains
subroutine foo(B)
real, intent(in) :: B
end subroutine
end module

0 Kudos
1 Reply
Steven_L_Intel1
Employee
271 Views
Hmm. That "Any associated actual argument must be an expression" isn't correct. A variable is fine. INTENT(IN) says that the called procedure does not redefine or change the definition status of the argument. The compiler can use this information in optimization.

I will ask the writers to remove that text. Thanks for pointing it out.
0 Kudos
Reply