Subject: Re: slightly off topic: [*]
To: Perry E. Metzger <>
From: Ian Lance Taylor <>
List: tech-toolchain
Date: 09/22/2005 22:42:04
"Perry E. Metzger" <> writes:

> Slightly off topic but I figure this is as good a place to ask as any
> -- does anyone here understand what the C99 "[*]" syntax is for? So
> far I've asked lots of smart people and no one can answer.

Do you mean, what does it mean?  Or do you mean, why does it exist?

I can tell you what it means.  It can be used in a function prototype
to mean that the parameter is a variable length array but that the
prototype does not say what the actual length is.  For example,
    int foo (int i, int a[*]);
is a prototype for a function which returns foo and takes two
parameters, one of type int and the other being a variable length
array.  You can't use [*] in a function definition.  In the
definition, you might say
    int foo (int i, int a[i]) { }
to mean that the variable length array a has i elements.

I'm not too sure why it exists.  I think the main advantage is when
you have a multi-dimensional array, as in
    int foo (int i, int j, int a[i][j]) { }
In that case there may be some advantage to being able to say in the
function prototype:
    int foo (int i, int j, int a[*][*]);
since that is in some sense different from:
    int foo (int i, int j, int **a);
Or maybe that's not the reason.  I'm not sure.

Of course variable length arrays, and the ability for a parameter to
refer back to an earlier parameter, are new in C99.