Re: Does the order of declarations matter?



<ejko123@xxxxxxxxx> wrote in message
news:1138214075.359667.137670@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

> More precisely, is the following code fragment standard-conforming:

> subroutine sub(dum,n)
> real,intent(inout):: dum(n)
> integer,intent(in):: n

> ! rest of sub
> end subroutine

> Or must the declaration for N appear before the declaration
> of DUM?

Obviously a trick question! Looking at ISO/IEC 1539-1:1997(E),
section 7.1.6.2:

"A variable in a specification expression shall have its type
and type parameters, if any, specified by a previous declaration
in the same scoping unit, or by the implicit typing rules in
effect for the scoping unit, or by host or use association. If
a variable in a specification expression is typed by the
implicit typing rules, its appearance in any subsequent type
declaration statement shall confirm the implied type and type
parameters."

Thus the place to look to decide standard conformance is the
host procedure or module that sets the default typing rules for
subroutine sub. If implicit none is in force there, or n
has implicit type that is not integer or kind type paraemter
that is not that of a default integer, the code is not
standard conforming. If there is no host, or the host implicitly
types n as a default integer, the code is OK.

> Related question: Is there a difference between

> subroutine sub2(iarray,n)
> integer,intent(in):: iarray(n),n

> and

> integer,intent(in):: n,iarray(n)

Section 7.1.6.2 goes on to say:

"If a specification expression includes a reference to an
inquiry function for a type parameter or an array bound of
an entity specified in the same specification-part, the type
parameter or array bound shall be specified in a prior
specification of the specification-part. The prior
specification may be to the left of the inquiry function in
the same statement. If a specification expression includes a
reference to the value of an element of an array specified in
the same specification-part, the array shall be completely
specified in prior declarations."

I think this means that the first declaration above is only
OK if n is implicitly default integer, but the second is
always OK because n is not an array. Umm... the last
paragraph above is changed by Corrigendum 2:

"If a specification expression includes a reference to an
inquiry function that depends on a type parameter or an array
bound of an entity specified in the same specification-part,
the type parameter or array bound shall be specified in a prior
specification of the specification-part. The prior
specification may be to the left of the inquiry function in
the same statement, but shall not be within the same entity-
decl. If a specification expression includes a reference to
the value of an element of an array specified in the same
specification-part, the array shall be completely specified in
prior declarations."

Doesn't seem to change my interpretation, though.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


.



Relevant Pages

  • Re: accessing arrays in a different sub-routine
    ... > I dynamically create an array from an expect output. ... This variable, having been declared lexical outside of any subroutine, ... You're trying to print the second element of an array ... one declaration near the top of the file, ...
    (comp.lang.perl.misc)
  • Re: Problem with array size
    ... > Who know how can I have in subroutine "titi" the size of the array ... change the declaration of the ... the subroutine needs what is called an "explicit interface". ...
    (comp.lang.fortran)
  • Alpaca Chap7 Question
    ... the declaration of the array my @files in the subroutine ... $starting_directories) calls the subroutine. ... array retains the list from the most previous call. ... sub gather_mtime_between { ...
    (perl.beginners)
  • Re: Array of Constants?
    ... >making it easy to access the proper parameters in the array. ... It cannot go in the declaration ... If I put it in the subroutine, ... Look at the Static keyword ...
    (microsoft.public.vb.general.discussion)
  • Numerical Recipes and allocate.
    ... I found subroutine where parameters are declared in the following way: ... END SUBROUTINE jacobi ... I.e. dimension of array was not given explicitly and between this ... declaration of variable and its usage "allocata" is not used. ...
    (comp.lang.fortran)