Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: strcpy ques...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 17 Topic 26073 of 26959
Post > Topic >>

Re: strcpy question

by Keith Thompson <kst-u@[EMAIL PROTECTED] > May 5, 2008 at 04:23 PM

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"
 




 17 Posts in Topic:
strcpy question
mdh <mdeh@[EMAIL PROTE  2008-05-05 11:19:59 
Re: strcpy question
Eric Sosman <Eric.Sosm  2008-05-05 14:39:35 
Re: strcpy question
=?ISO-8859-1?Q?Tom=E1s_=D  2008-05-05 11:39:39 
Re: strcpy question
David Thompson <dave.t  2008-05-19 03:59:51 
Re: strcpy question
Keith Thompson <kst-u@  2008-05-18 21:39:15 
Re: strcpy question
=?ISO-8859-1?Q?Tom=E1s_=D  2008-05-05 11:41:33 
Re: strcpy question
"Default User"   2008-05-05 18:47:03 
Re: strcpy question
mdh <mdeh@[EMAIL PROTE  2008-05-05 13:08:56 
Re: strcpy question
=?ISO-8859-1?Q?Tom=E1s_=D  2008-05-05 14:34:55 
Re: strcpy question
mdh <mdeh@[EMAIL PROTE  2008-05-05 16:04:37 
Re: strcpy question
"Default User"   2008-05-05 23:16:18 
Re: strcpy question
Keith Thompson <kst-u@  2008-05-05 16:23:24 
Re: strcpy question
mdh <mdeh@[EMAIL PROTE  2008-05-05 16:07:12 
Re: strcpy question
mdh <mdeh@[EMAIL PROTE  2008-05-05 16:52:00 
Re: strcpy question
Keith Thompson <kst-u@  2008-05-05 18:00:22 
Re: strcpy question
mdh <mdeh@[EMAIL PROTE  2008-05-05 16:52:33 
Re: strcpy question
mdh <mdeh@[EMAIL PROTE  2008-05-05 18:17:13 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 16:04:05 CDT 2008.