J3/01-148r1 To: J3 Date: 21st March 2001 Subject: Revised interp 000018 From: Malcolm Cohen ---------------------------------------------------------------------- NUMBER: 000018 TITLE: ELEMENTAL procedures with no arguments KEYWORDS: Elemental, procedure DEFECT TYPE: Erratum STATUS: J3 consideration in progress Section 12.7.2 of IS 1539-1:1997 seems to assume there is at least one argument to an elemental procedure. The semantics of the following examples do not seem to be clearly specified. Example 1: ELEMENTAL INTEGER FUNCTION f() f = 0 END Example 2: ELEMENTAL INTEGER FUNCTION g(i,j) INTEGER,INTENT(IN) :: i,j g = i + j END Example 3: ELEMENTAL INTEGER FUNCTION h(i) INTEGER,INTENT(IN),OPTIONAL :: i h = i END Example 4: ELEMENTAL SUBROUTINE s() REAL x,y,z x = 0 y = 0 z = x/y END QUESTION 1: What is the shape of a reference to function F in example 1? Is it scalar? QUESTION 2: If G() is referenced as G(iscalar,jarray(1:0)), the result is a zero-sized array. Is "iscalar" referenced (need it be defined)? Is the body of G() executed? QUESTION 3: What is the shape of a reference to H() if the argument is textually not present? QUESTION 4: When subroutine S is invoked, how many times is it executed? Is this example standard-conforming, or may a processor raise a divide-by-zero exception? ANSWER: (1) Yes, A reference to F() is intended to be scalar. A clarifying edit is supplied. (2) It is not possible to tell, in Fortran 95, whether the body of G() is executed, so that part of the question has no answer. [no edit required] Yes, ISCALAR must be defined; this is the same situation as writing ISCALAR + JARRAY(1:0) directly, with no user-defined ELEMENTAL procedure being used. [no edit required] (3) If the I argument to H is textually absent, a reference to H returns a scalar result (cf. answer to question 1). Note that execution of this procedure is not standard-conforming if the optional argument is not present. The "H = I" line should be replaced by IF (PRESENT(I)) THEN H = I ELSE H = 0 ! or some other desired scalar value END IF [no edit required] (4) The intention was that the subroutine is executed once per invocation. This is not clear from the standard; an edit is supplied to correct this oversight. However, the example is not standard-conforming on a processor whose arithmetic does not allow division by zero. [no edit required] EDITS: [206:10+] Insert "A reference to an elemental subroutine is not an elemental reference if the subroutine has no arguments present." {Specify zero-argument elemental subroutine reference.} [214:28] After "If" insert "there are no actual arguments or". {Clarify zero-argument elemental function reference.} SUBMITTED BY: Malcolm Cohen HISTORY: 98-117 m144 Submitted 00-123 m152 Revised by submitter but withdrawn for further study without vote. 01-148 m156 passed unanimously as amended ---------------------------------------------------------------------- ===END