(j3.2006) (SC22WG5.5519) Assignment to ero-sized strings and arrays

Bill Long longb
Tue Jun 16 17:48:36 EDT 2015


On Jun 16, 2015, at 4:13 PM, Walt Brainerd <walt.brainerd at GMAIL.COM> wrote:

> OK, I agree with Malcolm that just because there are false
> statements in the standard, it doesn't mean implementors
> will follow them.
> 
> But to make the standard consistent, the following should be added:
> 
> No value is assigned to the variable if it is of type integer, real, or
> complex and its value is zero.

This seems deficient in that derived types are not included, and also redundant, and hence unnecessary. 

...

> 7.2.1.3(1) of the F08 standard says:
> 
> No value is assigned to the variable if it is of type character and zero
> length, or is an array of size zero.

This is a much better statement. 

> 
> It is still in N2014, if that is the latest.
> 
> Consider the program:
> 
> program f
> character(len=:), allocatable :: c
> c = ""
> print *, len(c), "X"//C//"X"
> c = "QQQ"
> print *, len(c), "X"//C//"X"
> end program f
> 
> The sentence quoted says that the second assignment does not
> assign the value QQQ because the length of c is zero. I don't
> think that is what is intended.

I don?t see why the length of c is zero for the second assignment.  C is allocatable.  Part of the assignment process is to deallocate C and reallocate it with length 3. [Two paragraphs after the sentence about zero-size objects].  Only after the variable C is allocated does the definition occur.  At that point, the length is 3 and there is no issue.  Statements about ?type character and zero length? do not apply here.  Maybe we could add text to say that you don?t do the definition before the variable is deallocated, but that should be ?obvious?.  Doing the definition while it is deallocated is already not allowed. 

Cheers,
Bill



> 
> Just delete the sentence' it was silly, but wasn't wrong in F95.
> 
> -- 
> Walt Brainerd
> 
> 
> 
> -- 
> Walt Brainerd
> _______________________________________________
> 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