[Patch, Fortran, F08] PR45290: pointer initialization

Tobias Burnus burnus@net-b.de
Tue Aug 17 22:55:00 GMT 2010


  Janus Weil wrote:
> FAIL: gfortran.fortran-torture/execute/ptr.f90 compilation,  -O0
> FAIL: gfortran.dg/c_loc_tests_14.f90  -O  (test for excess errors)
> FAIL: gfortran.dg/c_loc_tests_5.f03  -O  (test for excess errors)
> FAIL: gfortran.dg/pointer_assign_4.f90  -O0  (test for excess errors)
> FAIL: gfortran.dg/pr43984.f90  -O  (test for excess errors)
> FAIL: gfortran.dg/subref_array_pointer_1.f90  -O0  (test for excess errors)
>
> All of them, except the C_LOC ones, fail on pointer assignments. And I
> think all of them are actually invalid.

At least NAG f95 accepts them all.


+++ gcc/testsuite/gfortran.dg/pr43984.f90 (working copy)

-  real(kind=kind(1.0d0)), dimension(:), pointer :: Izz
-      Izz =>  Iz(:,z)


That looks perfectly valid, cf. below.

-    integer(c_int), dimension(:), pointer :: int_ptr
-    my_c_ptr = c_loc(int_ptr(0))


Well, as written is is invalid - but change it to

-    integer(c_int), dimension(:), pointer :: int_ptr
ALLOCATE(int_ptr(0:10))
-    my_c_ptr = c_loc(int_ptr(0))


Then it is valid. Note: "int_ptr(0)" is not a pointer but "int_ptr(0)" 
is the first element of the array to which int_ptr points. That array is 
unnamed but has the TARGET attribute. If you want to have a named 
target, use:

integer, target :: tg(0:10)
-    integer(c_int), dimension(:), pointer :: int_ptr
int_ptr =>  tg
-    my_c_ptr = c_loc(int_ptr(0))

In this case int_ptr(0) is the first element of "tg" and "tg" has the 
TARGET attribute.

Tobias



More information about the Fortran mailing list