J3/98-175 Date: 1998/07/06 To: J3 From: Henry Zongaro Subject: Interp. question on default initialization in scope of module NUMBER: TITLE: Default initialization of variables declared in the scope of a module KEYWORDS: Default initialization, Use association, Modules, Derived Types DEFECT TYPE: STATUS: J3 consideration in progress QUESTION: Consider the following program. MODULE MOD TYPE DT INTEGER :: I = 17 END TYPE DT TYPE(DT) :: S END MODULE MOD PROGRAM P CALL SUB CALL SUB END PROGRAM P SUBROUTINE SUB USE MOD PRINT *, S S = DT(99) END SUBROUTINE SUB 14.7.3 states, in part, that: "The following variables are initially defined: . . . (3) Nonpointer direct components of variables of a type in which default initialization is specified for those components, provided that the variables are not accessed by use or host association, do not have the ALLOCATABLE attribute or POINTER attribute, and either have the SAVE attribute or are declared in a main program, MODULE, or BLOCK DATA scoping unit, and . . . ." 14.7.5 states, in part, that "Variables become defined as follows: . . . (19) Invocation of a procedure that contains a nonsaved local object that is not a dummy argument, is not accessed by use or host association, has neither the ALLOCATABLE nor POINTER attribute, and is of a derived type in which default initialization is specified for any direct components, causes those components of the object to become defined." 14.7.6 states, in part, that "Variables become undefined as follows: . . . (3) The execution of a RETURN statement or an END statement within a subprogram causes all variables local to its scoping unit or local to the current instance of its scoping unit for a recursive invocation to become undefined except for the following: (a) Variables with the SAVE attribute. . . . (e) Variables accessed from a module that also is referenced directly or indirectly by at least one other scoping unit that is making either a direct or indirect reference to the subprogram." Thus, according to 14.7.3, the value of S%I is 17 initially. 14.7.6 indicates that S becomes undefined upon execution of the END statement in the first instance of SUB, since default initialization does not confer the SAVE attribute. 14.7.5 indicates that invocation of a procedure does not cause use associated variables to become defined, so it seems that S remains undefined at the second instance of SUB. Is this program standard-conforming? If so, what should be the output of this program? ANSWER: EDIT: SUBMITTED BY: Henry Zongaro HISTORY: 98-175 m146 Submitted