variable length arrays and function definitions (fwd)

Tom MacDonald uunet!fig.cray.com!tam
Tue Dec 17 21:34:24 PST 1991


> If we consider a similar example of a definition,
> 
> 	    typedef int a;
> 
> 	    int foo (a, int n; double a[n]) { ... }
> 
> there is no ambiguity.  Just looking at `int foo (a,' determines the
> parsing.  If `a' were a type, it would have to be followed by
> something other than a comma.
> 
> The reason I feel sure of this is that all ANSI C compilers handle a
> very similar construct required by ANSI C:
> 
> 	    typedef int a;
> 
> 	    int foo (a, n) int a, n; { ... }
> 
> ANSI C says that `a' is a parameter.  ANSI C compilers
> can tell that `a' is a parameter when they see the comma;
> there is no need to parse any further.

I believe the ANSI (and ISO) C standard do not bless this construct.
I ran it through the `gcc' compiler and got

	z.c:3: parse error before `n'
	z.c: In function f:
	z.c:4: declaration for parameter `n' but no such parameter
	z.c:4: declaration for parameter `a' but no such parameter

as diagnostics.  The rule of thumb is - if it can be interpreted
as a type name then it is interpreted as a type name.

Tom MacDonald



More information about the Numeric-interest mailing list