Quantcast
Channel: Intel® Software - Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2746

Allocating an allocatable array in an assignment sentence produces unexpeted results or segfaults

$
0
0

Dear forum and Intel developers,

Consider the following code:

program hello
    implicit none
    real(kind=8), allocatable, dimension(:) :: x,y
    x=reshape((/1,2,3,4,5,6/),(/6/))
    print *,x
end program

It will produce blank output. The rememdy is to explicitly allocate x before the reshape statement.

Now the following:

program hello
    implicit none
    integer :: istat
    real(kind=8), allocatable, dimension(:) :: x,y
    allocate(x(60),stat=istat)
    call random_number(x)
    y=sin(x)
    print *,y
end program

It sometimes produces blank output, and sometimes it produces segfaults.

As long as I know, in Fortran 2003 allocatable arrays can be allocated dynamically in a statement.


Viewing all articles
Browse latest Browse all 2746

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>