(j3.2006) Some colleagues wish they could count on these working

Bill Long longb
Mon Sep 9 21:31:55 UTC 2013


If you are collecting data points:

At default optimization, the Cray compiler creates this executable output:

 > ./a.out
Ought to print "One":
One
Might not print "Two", "Three", and "Four":
Two
??i
??i


At -O0 (no optimization)

 > ./a.out
Ought to print "One":
One
Might not print "Two", "Three", and "Four":
Two
Three
Four

You are right to caution your colleagues to "not count on it".

Cheers,
Bill



On 9/9/13 3:17 PM, Van Snyder wrote:
> The small program below is a microcosm of something some of my
> colleagues are trying to do, especially the subroutine R4.
>
> I pointed out that 12.5.2.4p11 says R1 will work, but R2, R3, and R4 are
> not conformant.  So far, every processor they have that understands
> deferred character length behaves as they hope, but I warned them not to
> count on it.
>
> module Pointer_Target_Test_m
>
>    implicit NONE
>    private
>
>    public :: P, R
>
>    character(len=:), pointer :: C
>
> contains
>
>    subroutine R ( A )
>      character(*), intent(in), target :: A
>      c => a(:len_trim(a))
>    end subroutine R
>
>    subroutine P
>      print '(a)', c
>    end subroutine P
>
> end module Pointer_Target_Test_m
>
> program Pointer_Target_Test_p
>
>    use Pointer_Target_Test_m, only: P, R
>
>    print '(a)', 'Ought to print "One":'
>
>    call r1
>    call p
>
>    print '(a)', 'Might not print "Two", "Three", and "Four":'
>
>    call r2
>    call p
>    call r3
>    call p
>    call r4
>    call p
>
> contains
>
>    subroutine r1
>      character(*), parameter :: V0 = 'One'
>      character(len(v0)), target :: V1 = v0
>      call r ( v1 )
>    end subroutine r1
>
>    subroutine r2
>      character(*), parameter :: V0 = 'Two'
>      character(len(v0)) :: V1 = v0
>      call r ( v1 )
>    end subroutine r2
>
>    subroutine r3
>      character(*), parameter :: V0 = 'Three'
>      call r ( v0 )
>    end subroutine r3
>
>    subroutine r4
>      call r ( 'Four' )
>    end subroutine r4
>
> end program Pointer_Target_Test_p
>
> Does anybody not effectively give constants the SAVE attribute?
>
> Does anybody actually kill pointers according to 12.5.2.4p11 if the
> target is a constant or has the SAVE attribute, at least not in "check
> for undefined pointers" mode?
>
> It would be helpful if literal and named constants effectively had the
> SAVE attribute, and pointers whose targets ultimately are effective
> arguments with the SAVE attribute do not become undefined as specified
> in 12.5.2.4p11.
>
>
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
>

-- 
Bill Long                                           longb at cray.com
Fortran Technical Support    &                 voice: 651-605-9024
Bioinformatics Software Development            fax:   651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101





More information about the J3 mailing list