Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

fortran - Allocatable array valued function. gfortran vs ifort

Why is there different behavior between ifort and gfortran here? Compiled with ifort it returns false and with gfortran true. I ran into this problem before in my own code and decided to use a subroutine instead, but a recent question made me question this behavior.

function allocateArray(size)
    integer, allocatable, dimension(:) :: allocateArray
    integer size

    allocate(allocateArray(size))

end function allocateArray

From the main program

integer, allocatable, dimension(:) :: a

a = allocateArray(10)
print *, allocated(a)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When compiling with ifort before version 17.0.1, the default behaviour is for the compiler not to use the Fortran rules for automatic allocation on intrinsic assignment.

You will need to use an option like -assume realloc-lhs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...