ISO/IEC JTC1/SC22/WG5 N1465 Suggested Interpretations III John Reid 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 Since the declaration of ARRAY depends on the value of MAX_SIZE, is it valid to only allow access to ARRAY? 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 MODULE 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. Since OUTER depends on the definition of INNER, is it valid to only allow access to OUTER? If it is not valid, is it only an error if something in the main program actually tries to use OUTER? Can you write a structure constructor for OUTER in the main program? 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 MODULE In this example, only the variable VAR from the module is accessible; its type is not. Is this valid? If it is valid, can only the structure name VAR be referenced or can its components also be referenced? 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. Since the declaration of ARRAY depends on the value of MAX_SIZE, is it valid to only allow access to ARRAY? Is the array constructor for ARRAY, for example, accessible to the main program? ANSWER: Example 1: Yes, ARRAY is accessible, including its size, so an array constructor of size 100 may be used in an assignment statement for ARRAY. Example 2: Yes, it is valid to access only OUTER and declare objects of type OUTER. However, no access to the component COMP of such an object is permissible in MAIN. The inaccessibility of an entity whose type is PRIVATE (40:41-43) is intended to apply whenever the type is inaccessible. The edit makes this clear. Example 3: No, this is not valid. The inaccessibility of an entity whose type is PRIVATE (40:41-43) is intended to apply whenever the type is inaccessible. The edit makes this clear. Example 4: Yes, it is valid to allow access only to ARRAY. ARRAY is accessible, including its size, so an array constructor of size 100 may be used in an assignment statement for ARRAY. EDIT: In Section 4.4.1, add a new paragraph after line 43 of page 40 [40:43+]: If a type in a module is not accessible, the structure constructor (4.4.4) for the type, any entity that is of the type, and any procedure that has a dummy argument or function result that is of the type are not accessible. The structure constructor for an accessible derived type is not accessible if any of its ultimate components is not accessible. SUBMITTED BY: Larry Rolison HISTORY: 94-038 m128 submitted WG5 N1465 Draft answer.