forward declarations in function prototype.

H. Murakami uunet!tansei.cc.u-tokyo.ac.jp!mhiroshi
Thu Jul 16 13:25:29 PDT 1992


In ANSI FORTRAN 77 standard,  there is also the similar story.

ANSI X3.9-1978, ISO 1539-1980 (E)
5.1.1.1 
.....
The lower and upper dimension bounds are arithmetic
expressions, called dimension bound expressions, in which
all constants, symbolic names of constants, and variables
are of type integer. The upper dimension bound of the last
dimension may be an asterisk in assumed-size array
declarators (5.1.2) A dimension bound expression must not
contain a function of array element reference. Integer
variables may apper in dimension bound expressions only in
adjustable array declarators (5.1.2).

If the symbolic name of a constant or variable that appears
in a dimension bound expression is not of default implied
integer type (4.1.2), it must be specified as integer by an
IMPLICIT statement or a type-statement prior to its
appearance in a dimension bound expression.
.....


----------
* This is OK
      subroutine sub1 ( a, n )
      real a(n)
      ....
----------
* This is OK
      subroutine sub2 ( a, n )
      real a(n)
      integer n
      ....
--------------
* This is OK
      subroutine sub3 ( a, c )
      integer c
      real a(c)
      ....
--------------
* This is NOT
      subroutine sub4 ( a, c )
      real a(c)
      integer c
      ....
--------------
* This is OK
      subroutine sub5 ( n, a )
      implicit character(a-z)
      integer n
      real a(n)
      ....
--------------
* This is NOT
      subroutine sub6 ( a, n )
      implicit character(a-z)
      real a(n)
      integer n
      ....
--------------
* This is NOT
      subroutine sub7 ( n, a )
      implicit character(a-z)
      real a(n)
      integer n
      ....

So, why shouldn't we just borrow this simple quick convension
when we can use K&R style argument declarations.
Everything can be similar to FORTRAN.

In the case of prototype declaration,
	Every expression appeared inside [] must be a
	integer arithmetic expression (we have not yet powering in C.)
        consistes of integer quantities. {constant, variable}
	(probably it would be better to aboid array reference,
	 member of structure .....) 
	 May be we can use cast extended with scope like: 
		(extern)
		(extern char)
	 to specify explicitly something is external to the procedure.


      void suba ( int n, float a[n] ); /* n is the size of array. */
      void subb ( float a[n], int n ); /* n is the size of array. */

      int n;
      void sub0 ( float a[(extern)n][n], int n ); /* external n is 1-st dim.*/
       or
      void sub0 ( float a[(extern)n][(intern)n], int n ); /* ?? */

      corresponds to 
	 SUBROUTINE SUB0 ( A, N )
	 COMMON /COM/NN
	 REAL A(0:NN-1,0:N-1)
	 or
	 REAL A(0:N-1,0:NN-1)

---------
			Hiroshi Murakami
			mhiroshiatansei.cc.u-tokyo.ac.jp
				Have a good hack.



More information about the Numeric-interest mailing list