J3/98-143 Page 1 of 1 To: J3 From: Werner Schulz Subject: Language Regularization: Declarations Date: 26 February 1998 Fortran has a number of inconsistencies when it comes to declaring various entities and a subset is the topic of this paper. This subset is easily removed by a few editorial changes in the draft. One addition concerning the USE statement requires a little bit more editorial work. None of the suggested changes will affect existing codes. The following general principles should apply: 1. Any attribute that can effect data objects or procedures or interfaces can be specified as an attribute-specification in the declaration (and as a separate attribute-statement). 2. Any declaration statement can contain the optional :: Since the following only concerns the more modern notation introduced in F90 only examples in that notation will be given. The employed style is used to highlight the topic. To 1: The current F90/95 rules allow the following declarations: Real, PARAMETER :: a Real, SAVE :: x Real, TARGET, ALLOCATABLE :: x(:) ! etc ! Declaring variables of some type Type(atype), PARAMETER :: T Type(atype), ALLOCATABLE :: S(3) ! Defining a TYPE Type, PUBLIC :: atype END Type atype BUT the following declarations do not follow principle 1 for no apparent reason, esp. the attributes PUBLIC and PRIVATE have to be specified in a separate statement: Real FUNCTION foo END FUNCTION foo PUBLIC :: foo SUBROUTINE sub END SUBROUTINE sub PUBLIC :: sub INTERFACE if END INTERFACE if PUBLIC :: if INTERFACE OPERATOR(.op.) END INTERFACE OPERATOR(.op.) PUBLIC :: OPERATOR(.op.) ! similarly ASSIGNMENT USE amodule I suggest that the language allows the syntax of the following examples as well: Real, FUNCTION, PUBLIC :: foo END FUNCTION foo ! some additional attributes are allowed for FUNCTION SUBROUTINE, PUBLIC :: sub END SUBROUTINE sub INTERFACE, PUBLIC :: if END INTERFACE if INTERFACE, PUBLIC :: OPERATOR(.op.) END INTERFACE OPERATOR(.op.) ! similarly ASSIGNMENT USE, PRIVATE :: amodule ! This new form requires a little more editorial work. ! The statement means that all imported variables and procedures ! from amodule are not exported when the host is used. This would result in the following very regular declarations: Real, PARAMETER, PUBLIC :: a Real, variable, PUBLIC :: x Real, FUNCTION, PUBLIC :: foo() The "variable" is only introduced to highlight the regularity, it is not suggested as a new attribute. This also shows that the attributes are not all of the same quality, PARAMETER, FUNCTION, SUBROUTINE belong into one group as they are mutually exclusive, etc. The general declaration (only F90 style) can hence be specified as [type-spec,] [PARAMETER or FUNCTION or SUBROUTINE or INTERFACE or USE,] [other attribute-spec] :: name [(arguments) [RESULT clause] or initial expression] The order given above seems natural but is not mandatory. To 2: This principle is suggested as it is a natural consequence of 1, esp. the TYPE, FUNCTION, SUBROUTINE, INTERFACE declarations. A few examples will suffice, others have been given in 1. Examples: MODULE :: A END MODULE A USE :: A, ONLY: x, y USE, PRIVATE :: A ! This makes all imported variables and procedures PRIVATE ! i.e. they are not visible outside the host. PROGRAM :: Test END PROGRAM Test