FORTRAN IN argument modified

FORTRAN IN parameters should not be modified.

Declaring an argument as an "IN" argument indicates the intention to use this argument as a pure input parameter. However, this does not alter the fact that all FORTRAN arguments are passed by reference. Therefore, modifying the formal parameter will modify the actual argument, even if it is marked as "IN."

ID

Observation

Description

1

Definition

The place the argument was defined

2

Bad memory write

The place the argument was modifed

Examples


subroutine IModifyMyArg(k)
    integer :: k
    k = k+1
end

subroutine TestProc(i)
    integer, intent(in) :: i
    call IModifyMyArg(i)
    ! argument "i" is INTENT(IN) dummy argument
    ! but it is modified by IModifyMyArg
    print *,i
end

integer :: j
read *,j
print *,j
call TestProc(j)
print *,j
end
        

Copyright © 2010, Intel Corporation. All rights reserved.