I remember I read somewhere (on the net) that it is possible to define a pointer component that is pointed to some other module variable via compile-time initialization, for example:
module test_m
implicit none
integer, target :: arr_global( 3 )
type Mytype
integer, pointer :: arr(:) => arr_global
endtype
end module
program main
use test_m
implicit none
type(Mytype) :: m1, m2
m1 % arr(:) = [1,2,3] !! segmentation fault
!! print *, m2 % arr(:)
end
However, although the above code compiles with gfortran-11 (on Ubuntu22), it fails with segmentation fault (invalid memory reference). Is my syntax above incorrect, or am I doing something invalid…?
@septc, can you please share what fraction of your work involves Fortran and how much of it depends on gfortran? With your expertise with different languages, perhaps you can start submitting gfortran issues at GCC Bugzilla and, more importantly, develop and submit patches to the bugs?
Given your apparent use of gfortran on Linux and/or macOS, and also what appears to be those of several other readers here at Fortran Discourse, gfortran users can do with becoming active developers of gfortran. The gfortran-specific issue you’ve uncovered here is a perfect example.