J3/00-123 Date: 24th February 2000 To: J3 From: Malcolm Cohen Subject: Interpretation Request on ELEMENTAL procedures (revised) NUMBER: 18 ? TITLE: ELEMENTAL procedures with no arguments KEYWORDS: Elemental, procedure DEFECT TYPE: STATUS: 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 h2(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 H2() 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 scalar. Section 12.7.2 [214:28-29] says that "If the actual arguments are all scalar, the result is scalar." (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 H2 is textually absent, a reference to H2 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 subroutine is executed once per invocation. This is because any reference to the subroutine has no array arguments and so is not an "elemental reference" (section 12.4.3 [7-10]) but a normal subroutine reference. The example is not standard-conforming on a processor that does not allow division by zero. [no edit required] EDITS: None. SUBMITTED BY: Malcolm Cohen HISTORY: 98-117 Submitted 152-mjc-d Revised ===END