mdh <mdeh@[EMAIL PROTECTED]
> writes:
> On May 5, 2:34 pm, Tomás Ó hÉilidhe <t...@[EMAIL PROTECTED]
> wrote:
>> A function cannot take an array as a parameter. If you do the
>> following:
>
> Sorry if I was unclear...as this is what I was trying to say. In other
> words, a function that **expects** an array, will in fact **actually**
> receive a pointer as a parameter. So, what I was concentrating on was
> the syntax where a pointer that had an array allocated to it ( ie was
> not an array that had been converted to a pointer as an argument to a
> function) is just as legal a construct under as passing an array
> itself.
First, a point about terminology: a parameter is an object, local to a
function, declared in the function's declaration (for example argc and
argv in main()); an argument is an expression passed to a function in
a call.
There is no such thing in C as a function that expects an array.
A C function that *looks* like it expects an array argument, such as:
void foo(char arr[]) { /* whatever */ }
or even
void foo(char arr[42]) { /* whatever */ }
actually expects a pointer argument; both of the above is exactly
equivalent to:
void foo(char *arr) { /* whatever */ }
Using array *syntax* in a parameter declaration probably suggests that
the pointer argument should point to the first element of an array,
but any such suggestion has no more actual force than a comment.
The fact that C allows a parameter to be declared with array syntax,
and that such a parameter declaration is really no different from a
pointer parameter declaration, is IMHO unfortunate. It's mildly
convenient to be able to say that the argument is intended to be a
(converted) array, but the cost is increased confusion.
In a function call, it's not possible to have an expression of array
type as an argument. Any such expression will be converted to a
pointer, and the called function has absolutely no way of knowing
whether such a conversion has happened. (There are contexts in which
this conversion doesn't happen, but a function argument cannot be one
of those contexts.)
--
Keith Thompson (The_Other_Keith) <kst-u@[EMAIL PROTECTED]
>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


|