Print

Print


Hi,

I've encountered a "feature" in the SGI MipsPro F90
compiler and would like to know what other compilers
make of this, and whether the behaviour of the SGI
compiler conforms to the standard.

Attached find a short test program that tests the
behaviour of a variable initialized at declaration time,
vs. one initialized in a separate statement (itest1 and
itest2 respectively).  The variable that's initialized
at declaration time behaves exactly like a "saved"
variable even though there's no save statement in the code.
Is this expected behaviour?  It seems counter-intuitive
to me.  I've spent the last two weeks tracking this
one down, looking for a non-existent memory stomp.  Grrrr.

A colleague of mine found the following statement in
the SGI documentation which clearly points out this
feature so it's not a bug per se.  I don't find this
behaviour obvious though.

    "Initialization of a variable in a type declaration
     statement or any part of a variable in a DATA statement
     implies that the variable has the SAVE attribute unless
     the variable is in a named common block."

Test Code:

SUBROUTINE SUB1(INDX)

IMPLICIT NONE

INTEGER, INTENT(IN)  :: INDX
LOGICAL              :: ITEST1 = .TRUE.
LOGICAL              :: ITEST2

itest2 = .true.

if (mod(indx,5) == 0) then
   itest1 = .false.
   itest2 = .false.
endif

write(*,'(a,i,l,l)') 'indx, itest1, itest2 = ',indx,itest1,itest2

RETURN
END SUBROUTINE SUB1

PROGRAM TEST

INTEGER              :: INDX

do indx = 1,10
   call sub1(indx)
end do

STOP
END PROGRAM


Test Output:

indx, itest1, itest2 =            1 T T
indx, itest1, itest2 =            2 T T
indx, itest1, itest2 =            3 T T
indx, itest1, itest2 =            4 T T
indx, itest1, itest2 =            5 F F
indx, itest1, itest2 =            6 F T
indx, itest1, itest2 =            7 F T
indx, itest1, itest2 =            8 F T
indx, itest1, itest2 =            9 F T
indx, itest1, itest2 =           10 F F

Thanks for any enlightenment,

Catherine

--
-------------------------------------------------------------------------

Catherine Moroney            phone : (818) 393-3392
Jet Propulsion Laboratory    fax   : (818) 393-3134
MailStop 168-414             email : [log in to unmask]
4800 Oak Grove Drive
Pasadena, CA  91109-8099