Fortran array pointers to scalar -


in fortran, can reshape arrays pointers:

program working    implicit none    integer, dimension(:,:), pointer :: ptr   integer, dimension(6), target :: trg    trg = (/1,2,3,4,5,6/)   ptr(1:2,1:3) => trg    ! here, can use 6-sized 1d array trg   ! or 2 3-sized 2d array ptr @ same time.   ! both have same content (6 integers), indexed   ! differently.    write(*,*) ptr(1,2)  end program working 

this program writes "3", according reshape rules.

similarly, attempted same, not 1d 2d, 0d 1d.

program not_working    implicit none    integer, dimension(:), pointer :: ptr   integer, target :: trg    trg = 1   ptr(1:1) => trg    ! hoped able use scalar trg @ same time   ! one-sized 1d array ptr. thought both have same   ! content, indexed differently.    write(*,*) ptr(1)  end program not_working 

i expected see "1". not compile.

gfortran 4.9 says:

error: rank remapping target must rank 1 or contiguous @ (1)

ifort 14.0.2 says:

<file>.f90: catastrophic error: internal compiler error: segmentation violation signal raised please report error along circumstances in occurred in software problem report. note: file , line given may not explicit cause of error. compilation aborted <file>.f90 (code 1)

i not understand how scalar trg can not contiguous , fundamental difference between 2 example programs is.

the scalar not contiguous array because not array @ all. simple that. gfortran detects , complains, ifort confused , crashes. code invalid, cannot point array pointer on scalar.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -