(j3.2006) (SC22WG5.4185) Please say this isn't allowed!

Bill Long longb
Fri Feb 12 18:18:11 EST 2010



Reinhold Bader wrote:
> Hello,
> 
> referring to the 2003 standard, I think this is illegal due to 12.4.1.2 
> (p270,  20-22).:
> "If the dummy argument has the TARGET attribute and the corresponding 
> actual argument does not
> have the TARGET attribute or is an array section with a vector 
> subscript, any pointers associated with
> the dummy argument become undefined when execution of the procedure 
> completes."
> 
> Regards
> Reinhold
> 
> N.M. Maclaren schrieb:
>> While writing a paper on C interoperability, I was checking on Fortran's
>> equivalents to some C facilities, and I cannot find anything that forbids
>> this.  NAG objects to it, but Intel and Pathscale allow it - or, at 
>> least,
>> let it happen ....
>>

As noted in the citation from Reinhold above, the code is non-conforming 
because of the

     PRINT *, p

statement, as a pointer with an undefined association status cannot be a 
list item in an I/O statement.  However, this is not one of the 
transgressions that the compiler is required to detect, so the 
implementation is free to do anything it wants.  One version of 
"anything" for this case would be to leave the association status of p 
unchanged at the end of Fred, resulting in

 > ./a.out
  1.,  2.,  3.

All of Cray, PGI, Pathscale, Intel, and gfortran produce this output 
(with varying amount of spacing and trailing zero characters).

Cheers,
Bill


>> PROGRAM Main
>>    REAL, POINTER, DIMENSION(:) :: p => NULL()
>>    REAL :: x = 1.0, y = 2.0, z = 3.0
>>    CALL Fred ( (/ x,y,z /) )
>>    PRINT *, p
>> CONTAINS
>>    SUBROUTINE Fred (arg)
>>        REAL, TARGET, DIMENSION(:) :: arg
>>        p => arg
>>    END SUBROUTINE Fred
>> END PROGRAM Main
>>
>> Regards,
>> Nick Maclaren.
>>
> 
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://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