J3/01-312r2 Date: 22 August, 2001 To: J3 From: WG5 interps subgroup in London/Interp Subject: Interpretation F90/000164: draft response Changes since the original version, numbered the questions and answers. Changes from r1 to r2: fixes in answer 3a). NUMBER: F90/000164 TITLE: Use of ONLY with multipart definitions KEYWORDS: ONLY, module, derived type DEFECT TYPE: STATUS: J3 consideration in progress QUESTION: Sections 11.3.1 and 11.3.2, among others, describe how accessibility of data objects, derived type definitions, etc. can be controlled via the ONLY clause of the USE statement and via the PUBLIC and PRIVATE accessibility attributes/statements. But these sections do not describe what happens when a definition consists of multiple parts and only some of the parts have their accessibility controlled. Examples include, but are not limited, to the following: Example 1: MODULE MOD INTEGER, PARAMETER :: MAX_SIZE = 100 INTEGER, DIMENSION(MAX_SIZE) :: ARRAY END MODULE PROGRAM MAIN USE MOD, ONLY: ARRAY ... END PROGRAM QUESTION 1a) Since the declaration of ARRAY depends on the value of MAX_SIZE, is it valid to only allow access to ARRAY? QUESTION 1b) Is the array constructor for ARRAY, for example, accessible to the main program? Example 2: MODULE MOD TYPE INNER INTEGER I END TYPE TYPE OUTER INTEGER K TYPE(INNER) COMP END TYPE END MODULE PROGRAM MAIN USE MOD, ONLY: OUTER ... END PROGRAM The derived type OUTER in module MOD has a component of derived type INNER. However, when the main program accesses the module, it restricts access to only derived type OUTER. QUESTION 2a) Since OUTER depends on the definition of INNER, is it valid to only allow access to OUTER? QUESTION 2b) If it is not valid, is it only an error if something in the main program actually tries to use OUTER? QUESTION 2c) Can you write a structure constructor for OUTER in the main program? QUESTION 2d) If it is valid, can component I of substructure COMP be referenced? Example 3: MODULE MOD TYPE DEF INTEGER K REAL R END TYPE TYPE(DEF) VAR END MODULE PROGRAM MAIN USE MOD, ONLY: VAR ... END PROGRAM In this example, only the variable VAR from the module is accessible; its type is not. QUESTION 3a) Is this (example 3) valid? QUESTION 3b) If it is valid, can only the structure name VAR be referenced or can its components also be referenced? QUESTION 3c) If only the structure name VAR can be referenced, what is the meaning when the structure name is included in a namelist object list for input and/or output? Example 4: MODULE MOD INTEGER, PARAMETER :: MAX_SIZE = 100 INTEGER, DIMENSION(MAX_SIZE) :: ARRAY PRIVATE MAX_SIZE END MODULE PROGRAM MAIN USE MOD ... END PROGRAM Another way to limit access to items in modules is via the PRIVATE attribute/statement. QUESTION 4a) Since the declaration of ARRAY depends on the value of MAX_SIZE, is it valid to only allow access to ARRAY? QUESTION 4b) Is the array constructor for ARRAY, for example, accessible to the main program? ANSWER: 1a) Yes, ARRAY is accessible, including its size (via the SIZE intrinsic), even though MAX_SIZE is not accessible. 1b) An array constructor of size 100 may be used in an assignment statement for ARRAY. 2a) Yes, it is valid to access only OUTER and declare objects of type OUTER. 2b) Not applicable. 2c) Yes, the structure constructor may be used in the main program. For example, TYPE(OUTER) X,Y X%COMP%I = 65 Y = OUTER(13,X%COMP) 2d) Yes, component I of component COMP may be referenced. 3a) Yes, there is no requirement that a type name be accessible for an entity of that type to be accessible. 3b) Both VAR and its components may be referenced. 3c) Not applicable. These questions were resolved by interpretation 85, which made a clarifying edit to 14.1.2.5. 4a) Yes, it is valid to allow access only to ARRAY. 4b) ARRAY is accessible, including its size (via the SIZE intrinsic), so an array constructor of size 100 may be used in an assignment statement for ARRAY. EDIT: None. SUBMITTED BY: Larry Rolison HISTORY: 94-038 m128 submitted