Subject: Re: slightly off topic: [*]
To: Ian Lance Taylor <ian@airs.com>
From: Perry E. Metzger <perry@piermont.com>
List: tech-toolchain
Date: 09/23/2005 08:34:13
Ian Lance Taylor <ian@airs.com> writes:
> "Perry E. Metzger" <perry@piermont.com> 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.

Does this have any semantic distinction from the prototype saying

int foo(int i, int a[]);

at all? Compiled code has no way of knowing what the main function
might have inside the [] anyway, so it can't behave differently.

> 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.

Okay, so does *anyone* know? I've asked a lot of smart people who
*should* know and so far no one does.

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

*That* stuff I understand just fine...

-- 
Perry E. Metzger		perry@piermont.com