JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for COMP-FORTRAN-90 Archives


COMP-FORTRAN-90 Archives

COMP-FORTRAN-90 Archives


COMP-FORTRAN-90@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  March 2011

COMP-FORTRAN-90 March 2011

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: order of statements

From:

Yasuki Arasaki <[log in to unmask]>

Reply-To:

Fortran 90 List <[log in to unmask]>

Date:

Wed, 30 Mar 2011 16:41:24 +0900

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (122 lines)

"W.J. Metzger" <[log in to unmask]> wrote:
>> Type declarations, e.g.,  DoublePrecision d
>> dimensions, e.g.,         Dimension d(2)
>> common,                   common /c/ d
>> can appear in any order.  But giving a name to a constant, e.g.,
>>                            Parameter (k=5)
>> must appear before the first use of the named constant, i.e.,

I see your point. The processor needs to go through all the
specification statements to decide what a particular name represents
anyway. Why should an order be imposed for named constants?

I suppose the reason is historical.

In FORTRAN II, there are no type declaration statements, and no COMMON.
Only the DIMENSION statement is used to declare an array, so there is
not much concern here for order of specification statements [Note *1].

FORTRAN IV has type declarations but also retains the DIMENSION
statement. Because of this, it is not possible to give all information
about a name in a single statement. So, separate statements (COMMON,
EXTERNAL, DATA, ...) [Note *2] are used not only for DIMENSION but for
all other bits of information about a name. FORTRAN 66 does not
specify an ordering of specification statements, perhaps aiming for
maximum compatibility between processors [Note *3].

FORTRAN 77 adds the PARAMETER and IMPLICIT statements, and defines
particular ordering of these [Note *4]. Having named constant
values defined before use would make implementation easier.

So, my guess is that FORTRAN 66 allowed arbitrary ordering of
specification statements because it was more concerned with
portability of then existing code, and FORTRAN 77 imposed an
ordering on the new features because it was more concerned with
ease of implementation and with actually having the new features
added to implementations. [Note *5]
-----
[Note *1] In the FORTRAN II Programmer's Reference Manual, it says
"the DIMENSION statement must precede the first appearance of the
variable" (DIMENSION must be specified before use of array), but
"An EQUIVALENCE statement may be placed anywhere in the source program".
So apparently an EQUIVALENCE statement can be placed even after the
executable statements containing the EQUIVALENCEd variables. In the
statement
      EQUIVALENCE(A,C(5))
C is not necessarily an array. When C is not an array, C(5) is "the 4th
storage location in the object program after the cell containing C".
If C is an array of rank three (declared by a DIMENSION statement
preceding or following the EQUIVALENCE statement), C(5) is the 4th storage
location after the cell containing C(1,1,1).

[Note *2] In a DEC PDP-9 FORTRAN IV manual from 1968, it says
"All SPECIFICATION statements must appear before any executable
code generating statement. They must appear in this order:
type statements, DIMENSION statements, COMMON statements, and
EQUIVALENCE statements. EXTERNAL and DATA statements may appear
anywhere after all type statements and before the executable
code generating statements". So this implementation does require
a particular ordering, and code written without this particular
ordering in mind does not run on this processor. The FORTRAN 66
Standard perhaps tried to gain more portability by forcing processors
to relax such restrictions.

[Note *3] The DATA statement is not a "specification statement"
in FORTRAN 66, and a DATA statement must be placed after all the
specification statements. Since Fortran 90, the DATA statement
may be placed among other specification statements, but the type and
array properties must be established before a variable appears
in a DATA statement (or the variable must be a scalar of implicit
type). So the DATA statement always required a particular order
of placement.

[Note *4] The two other specification statements added in FORTRAN 77,
INTRINSIC and SAVE have no particular ordering defined, perhaps
because they work somewhat like FORTRAN 66's existing specification
statements.

[Note *5] There is another issue that is confusing.
The following is not accepted by gfortran and IBM's ifort.
      SUBROUTINE SUB(A,X)
      REAL A(X)
      INTEGER X
According to the error messages, X here is an implicit REAL variable
and it cannot be in an array-spec, despite the FORTRAN 66 Standard
saying "The appearance of a symbolic name in a type-statement serves
to inform the processor that it is of the specified data type for all
appearances in the program unit" and "In the absence of an explicit
declaration, the type is implied by the first character of the name",
and the FORTRAN 77 Standard saying essentially the same thing
(Sections 8.4 and 4.1.2). The FORTRAN 77 Standard additionally says
(in 4.1.1), "Once a particular name is identified with a particular
type in a program unit, that type is implied for any usage of the name
in the program unit that requires a type". It seems the ordering of
specification statements is significant in this context. I cannot
figure out what the Fortran 2008 Standard says on this matter.

The following is accepted by the two processors (gfortran and ifort):
      SUBROUTINE SUB(A,X)
      INTEGER X
      REAL A(X)
and so is
      SUBROUTINE SUB(A,N)
      REAL A(N)
      INTEGER N
The latter would appear at first sight that the ordering of the two
type declarations doesn't matter, but actually the type of N is
determined implicitly, and the INTEGER statement only confirms the
implicit type. Writing IMPLICIT NONE here makes the fragment
unacceptable.

On the same two processors (gfortran and ifort),
      COMMON /C/I,X
      DIMENSION I(2)
      DOUBLE PRECISION I
      REAL X
declares a common block that has five numeric storage units; the
first four taken up by the double precision array I.
In this context, the processor does look at all three statements
to decide what I and X is, and adding an IMPLICIT NONE has no effect.
-- 
Yasuki Arasaki
[log in to unmask]

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

September 2018
August 2018
July 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
December 2015
November 2015
October 2015
September 2015
August 2015
June 2015
April 2015
March 2015
January 2015
December 2014
November 2014
October 2014
August 2014
July 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
July 2013
June 2013
May 2013
April 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
August 2010
July 2010
June 2010
March 2010
February 2010
January 2010
December 2009
October 2009
August 2009
July 2009
June 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998
1997


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager