Talk About Network

Google





Programming > C - C++ Learning > Re: Using the s...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 22 Topic 4074 of 4400
Post > Topic >>

Re: Using the same source file from other source files

by Philip Potter <pgp@[EMAIL PROTECTED] > Mar 25, 2008 at 05:22 PM

Chris ( Val ) wrote:
> On Mar 21, 9:03 pm, Philip Potter <p...@[EMAIL PROTECTED]
> wrote:
>> Hal Vaughan wrote:
>>> So
>>> char *argv[]
>>> and
>>> char **argv
>>> are essentially the same?
>> They are *exactly* the same in a parameter list.
>>
>> Elsewhere the difference is clear - one is an array of 'char *'s, and
> 
>     Don't you mean: "a pointer to an array of char*" ?

No, I don't. The magical cdecl program tells me:

cdecl> declare foo as pointer to array of pointer to char
Warning: Unsup****ted in C -- 'Pointer to array of unspecified dimension'
         (maybe you mean "pointer to object")
char *(*foo)[]

The last line above is the syntax which you would use if pointers to 
arrays of unspecified dimension were sup****ted in C.

It also explains:

cdecl> explain char *argv[]
declare argv as array of pointer to char

To return to basics:

char x[10];
char *y;
char (*z)[10]

x is an array of 10 'char'. It is *not* a pointer, but in most contexts 
it acts like one. In such a context, the pointer value which x "decays" 
to is a pointer to x's first element, with the type of pointer-to-char 
or 'char *'. (These contexts include array subscripting x[i], arithmetic 
x+i, but exclude the 'sizeof x' and '&x').

y is a pointer to 'char'. It can also point to the first element of an 
array of char. This means that the syntax for using x and y are very 
similar, even though they are objects with different types.

If I assign y = x; then y now points to the first element of an array. 
However y is still a 'char *', that is, it points to a 'char', not to an 
array of char (a 'char []'). Although some people may sloppily now refer 
to y as a "pointer to x" or "pointer to an array", it is strictly 
pointing to x's first element, and it is a pointer to char.

z is a true pointer to an array of 10 'char'. If I assign z = &x; then z 
points to the whole x array. Pointers to arrays are not commonly seen. I 
can't think of a situation in which I have ever used one.
 




 22 Posts in Topic:
Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 07:10:47 
Re: Using the same source file from other source files
Richard Heathfield <rj  2008-03-20 07:25:59 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 07:29:28 
Re: Using the same source file from other source files
"Jim Langston"   2008-03-20 00:55:37 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-20 15:31:49 
Re: Using the same source file from other source files
Richard Heathfield <rj  2008-03-20 08:36:26 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 08:50:25 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 09:28:25 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 09:37:01 
Re: Using the same source file from other source files
"Chris ( Val )"  2008-03-21 03:37:07 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-25 17:22:35 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 15:08:23 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 15:37:26 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 15:48:02 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 15:56:20 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-20 17:11:20 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 17:54:57 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-21 10:03:58 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 19:34:41 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 20:31:21 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 19:45:49 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 20:34:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
localhost-V2008-12-19 Wed Jan 7 10:28:06 PST 2009.