This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
intent on derived types with pointer components
- From: Jacob Weismann Poulsen <jwp at dmi dot dk>
- To: fortran at gcc dot gnu dot org
- Date: Tue, 29 Sep 2009 14:36:30 +0200
- Subject: intent on derived types with pointer components
Hello Experts
I have a couple of questions to the code snapshot below (there no
purpose of the code
other than demonstrating the question I have) but before I pose them I
better explain that:
1) I have not been able to find a compiler (cf. options below) that warn
against
standard violations in the code below.
2) I have been told that the assignment w2%p(:) = w1%p(:) in bar2 (where w2
has intent(out) isn't legal fortran.
------------------------------cut-here------------------------------
module mty
implicit none
type pr1
real, pointer :: p(:)
end type pr1
type pr2
real, pointer :: p(:,:)
end type pr2
contains
subroutine bar(w1,w2)
implicit none
type (pr1), intent(in) :: w1
type (pr1), intent(inout) :: w2
w2%p(:)=w1%p(:)
end subroutine bar
subroutine bar2(w1,w2)
implicit none
type (pr1), intent(in) :: w1
type (pr1), intent(out) :: w2
w2%p(:)=w1%p(:)
end subroutine bar2
end module mty
program foo
use mty
implicit none
type(pr1), pointer :: x,y
type(pr2), pointer :: z
integer, parameter :: N=11,M=1479742
allocate(x,y,z)
allocate(x%p(M),y%p(M),z%p(N,M))
z%p = 8888888.
x%p => z%p(2,:)
call bar2(x,y)
call bar(x,y)
end program
------------------------------cut-here------------------------------
I believe that if bar and bar2 were constructed to take pure pointer
arguments,
i.e. instead of
type (pr1), intent(out) :: w2
then:
real, pointer, intent(out) :: w2(:)
then it wouldn't conform to any of the standards before the 2003
standard but
I'm less certain when it comes to derived types. Moreover, I'm less certain
about the capabilities that the compilers have in this respect, i.e. can I
generally trust that if none of the compilers are able to detect a standard
violation, then the code obeys the standard completely.
So, is it true that the assignment w2%p(:) = w1%p(:) in bar2 isn't legal
fortran and if so which of the standards (90,95,2003,..) does it violate (if
not all). I would be most grateful if you could point me to relevant pages
in these standards where I can read more about this violation.
If it's not legal, how come none of the compilers are able to catch it
((I can
imagine lengthy answers here, but I'm really curious)
Cheers, Jacob
-------------------------------------------------------------------------------
Appendix
-------------------------------------------------------------------------------
None of the compilers below warns about standard violations (I have tried
the latest versions of these compilers)
open64: openf90 -ansi -fullwarn -o open64_standard_question
standard_question.f90
sun: /data/sw/sunstudio_200709/sunstudio12/bin/f95 -ansi -u -o
sun_standard_question standard_question.f90
pgi: pgf90 -Minform=inform -Mstandard -o pgi_standard_question
standard_question.f90
intel: /data/sw/intel/Compiler/11.0/083/bin/ia32/ifort -O0 -stand f03 -o
intel_standard_question standard_question.f90
intel: /data/sw/intel/Compiler/11.0/083/bin/ia32/ifort -O0 -stand f90 -o
intel_standard_question standard_question.f90
gnu: gfortran -Wall -Wimplicit-interface -Wsurprising -std=f95 -o
gnu_standard_question standard_question.f90
gnu: gfortran -Wall -Wimplicit-interface -Wsurprising -std=f2003 -o
gnu_standard_question standard_question.f90
cray: ftn -O0 -m0 -Omsgs -Onegmsgs -o cray_standard_question
standard_question.f90
pathscale: ftn -ansi -fullwarn -o pathscale_standard_question
standard_question.f90
--
Jacob Weismann Poulsen <jwp@dmi.dk>
Fingerprint: 9315 DC43 D2E4 4F70 3AA8 F8F0 9DA0 B765 F5C8 7D26