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

Pointer to structure component

$
0
0

Using compiler versions:

Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.1.163 Build 20171018

GNU Fortran (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

In the short program below, which contains only declarations:

program pointer_to_component
implicit none
type data
   logical :: used= .false.
   real :: val
end type data
type(data), dimension(3), target :: vdat
type(data), pointer :: dat1p => vdat(1), dat2p => vdat(2), dat3p => vdat(3)
logical, pointer :: ldat1 => dat1p%used, ldat2 => dat2p%used, ldat3 => dat3p%used       ! DEC 1
logical, pointer :: ldat1 => vdat(1)%used, ldat2 => vdat(2)%used, ldat3 => vdat(3)%used ! DEC 2
end program pointer_to_component

Comment out either the line "DEC 1" or "DEC 2" for compilation.

With "DEC 1", ifort issues the error messages:

pointer_to_component.f90(9): error #8813: The target must have the TARGET attribute.   [DAT1P]
logical, pointer :: ldat1 => dat1p%used, ldat2 => dat2p%used, ldat3 => dat3p%used
-----------------------------^

with similar messages for ldat2 and ldat3.  However, gfortran compiles the code without complaining.

With "DEC 2", both compilers accept the code.

More interestingly, if I move the declarations into a module and make the conflicting pointer assignments in the program, as below:

module M_PtC
type data
   logical :: used= .false.
   real :: val
end type data
type(data), dimension(3), target :: vdat
type(data), pointer :: dat1p => vdat(1), dat2p => vdat(2), dat3p => vdat(3)
logical, pointer :: ldat1 => null(), ldat2 => null(), ldat3 => null()
end module M_PtC

program pointer_to_component
use M_PtC
implicit none
ldat1 => dat1p%used ; ldat2 => dat2p%used ; ldat3 => dat3p%used       ! DEC 1
end program pointer_to_component

Then both compiler accept the code.

I wonder, when ifort issues an error with the "DEC 1" line, is it following the standard (and thus gfortran is not), or is it a bug? Is it against the standard to assign a pointer to an object component, when the object itself is already a pointer?


Viewing all articles
Browse latest Browse all 2746