Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!adelie!axiom!drilex!carols From: carols@drilex.UUCP (Carol Springs) Newsgroups: comp.lang.fortran Subject: Re: Semantics of local variables Message-ID: <405@drilex.UUCP> Date: 31 Dec 87 12:01:08 GMT References: <2617@killer.UUCP> Reply-To: carols@drilex.UUCP (Carol Springs) Organization: Data Resources/McGraw-Hill, Lexington, MA Lines: 30 Keywords: semantics local variables DATA In article <2617@killer.UUCP> richardh@killer.UUCP (Richard Hargrove) writes: >A quick question for serious FORTRAN user's: do the semantics of initializing >a local variable in a DATA statement force the variable to have static >scope? That is, can you generally count on the variable retaining its value >across calls to the subroutine in which it's defined? I know this is the case >for some compilers, but can you count on it generally? F77 and no, I don't >have a copy of the standard. The ANSI standard for FORTRAN77 does not specify that DATA variables retain their values across subroutine calls. There are implementations of FORTRAN77 for which one cannot count on these variables' keeping the value most recently assigned to them in the subprogram--for example, Unisys A Series FORTRAN77 (unless the compiler control option OWN is set). If memory serves correctly, the default action in A Series FORTRAN77 is to restore the DATA-initialized values to all such variables every time the subroutine is invoked. If a variable is not changed within the procedure, the user sees the same value for the variable in each invocation, whether or not OWN is set. If, however, the variable is reassigned, different results can occur depending on the setting of OWN. Moral: Don't count on *any* local variables' keeping their values from one subprogram invocation to the next, especially if you want to ensure portability. Include the variables in SAVE statements if necessary. -- Carol Springs Data Resources/McGraw-Hill {rutgers!ll-xn, ames!ll-xn, mit-eddie!ll-xn, 24 Hartwell Avenue husc6!harvard, gatech!harvard, Lexington, MA 02173 linus!axiom, necntc} !drilex!carols