Does assignment count as uninitialised access?

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Fri Jun 8 20:44:00 GMT 2007


Terry Frankcombe wrote:
> Hi folks
> 
> On this list, lots of code snippets are declared invalid due to
> uninitialised access.  It makes me curious what the standard has to say
> about this.  Does copying count, if the copy is not subsequently
> accessed?  Consider the following:
> 
> program fred
> implicit none
> real,dimension(4)::a,b
> a(1)=1
> a(2)=2
> b=a
> write(*,*)b(1:2)
> end
> 
>>From the point of view of interpreting what's stored in a memory
> location, whatever junk that is initially to be found in a(3:4) is never
> referenced.  I'd view this as being in the spirit of "no uninitialised
> access", and indeed compiling and running this program performs as
> expected.  If it's in the spirit, is it in the letter of the law?

No.
   b=a
means
   b(1) = a(1); b(2) = a(2); b(3) = a(3); b(4) = a(4)
i.e. there are unitialized accesses, no matter if you use those values 
later on or not.  This is mandated by the standard.

Please note that this is not a forum for requesting interpretations of 
the standard, unless gfortran may be doing something wrong.

Cheers,
- Tobi



More information about the Fortran mailing list