J3/04-361
Date: 13 July 2004
To: J3
From: Richard Maine
Subject: Automatic arrays in interface bodies
NUMBER:
TITLE: Automatic arrays in interface bodies
KEYWORDS: automatic array, interface body
DEFECT TYPE: Erratum
STATUS: J3 consideration in progress
QUESTION: Is the following program standard-conforming.
program main
interface
subroutine sub(n)
integer, intent(in) :: n
real :: x(n)
end subroutine sub
end interface
call sub(2)
end program main
subroutine sub(n)
integer, intent(in) :: n
real :: x(n)
write (*,*) size(x)
end subroutine sub
The potential problem is the declaration of X in the
interface body.
According to C542
"An explicit-shape array whose bounds are not initialization
expressions shall be a dummy argument, a function result, or an
automatic array of a procedure."
The definition of an automatic array is
"An automatic array is an explicit-shape array that is declared in a
subprogram, is not a dummy argument, and has bounds that are not
initialization expressions."
Although the X in subroutine sub fits this definition, the X in the
interface body does not because an interface body is not a subprogram.
In 12.3.2.1, at [259:36-37], we have
"The specification part of an interface body may specify attributes
or define values for data entities that do not determine
characteristics of the procedure. Such specifications have no
effect."
The presumed reason for this is to allow the specification part of a
procedure to be copied into an interface body. If the declarations of
automatic arrays cannot be so copied, that would appear to negate the
reason for the feature.
ANSWER:
Yes. This was intended to be standard conforming. Edits are provided
to fix this error.
EDITS:
[78:23] "subprogram" -> "subprogram or interface body"
[78:21-22] "shall be... procedure." ->
"may be declared only in a subprogram or interface body."
{Note to J3. The second edit isn't really necessary, as the first
one solves the problem. I do think that the second edit majorly
improves the exposition compared to the circularity of the existing
words. As is, you read that an explicit shape array with some
conditions has to be an automatic array. You then see that an
an automatic array is an explicit shape array that isn't one of
the other kinds of explicit shape arrays, but is declared in a
subprogram (or interface body, after the first edit). Seems
simpler to just say in the first place that it has to be in a
subprogram (or interface body)...and then we don't need the
separate bit about dummy arguments and function results in the
constraint. Perhaps if you don't include this edit in the
interp answer, it might be considered for f2003+.}
TBD.
SUBMITTED BY: Richard Maine
HISTORY: 04-361 m169 Submitted