Re: embedded questions!!!




"Dave Hansen" <iddw@xxxxxxxxxxx> wrote in message
news:lglfs11e4ifgilnq2mh3d35ufjc8713mr2@xxxxxxxxxx
> On Fri, 13 Jan 2006 07:16:56 -0800 in comp.arch.embedded, "Richard
> Henry" <rphenry@xxxxxxxx> wrote:
>
> >
> >"John B" <spamj_baraclough@xxxxxxxxxxxxxxxxxxx> wrote in message
> >news:43c7b8d3$0$819$4c56ba96@xxxxxxxxxxxxxxxxxxxxxxxxx
> >> On 12/01/2006 the venerable Chuck F. etched in runes:
> [...]
> >> The two declarations:
> >>
> >> char str1* = "JHONSON";
> >>
> >> and
> >>
> >> char str2[] = "JHONSON";
> >>
> >> both allocate space for a modifiable string. The difference being that
the
> >first one also creates a
> >> pointer to that string.
> >
> >Isn't str2 also a pointer?
>
> No.
>
> Repeat after me: "Arrays are not pointers. Pointers are not arrays."
> Despite what you may have been told.
>
> A pointer is an object that references some other object.
>
> An array is a group of contiguously allocated objects of the same
> type.
>
> (This is the important bit) The unadorned name of an array devolves
> into a pointer to the first element of that array. Sort of like a
> compile-time constant.
>
> One point of confusion is the mechanism of array indexing. The syntax
> "a[i]" has *exactly* the same meaning as "(*a + i)" whether a is a
> pointer or array. So given the declarations above, str1[0] == 'J' ==
> str2[0].
>
> Another is the syntax for passing an array as a parameter to a
> function. Thus "Fn(str1);" looks to be much the same as "Fn(str2);"
> but the actual semantics are a bit different. Inside the function
> itself, of course, the parameter is the same in either case.
>
> >
> >BTW, I will admit a recurring problem with understanding the nuances of C
> >pointers.
> >
>
> Peter van der Linden's "Expert C Programming: Deep C Secrets" has one
> or two excellent chapters on the differences between arrays and
> pointers (as well as sections on understanding and contruction C
> declarations, and other topics introductory books are to timid to
> tackle). Somewhat dated (it was written about a dozen years ago), but
> very readable and recommended. You don't read it because you're an
> expert already, you read it to become expert...

I will defer to you knowledge of C pointers.

However, my confusion about them has only increased.


.



Relevant Pages

  • Re: char **argv & char *argv[]
    ... "pointer to pointer to char". ... >> pointer)) pointing to the first element of an array. ... so we have to start adding more context. ... type "pointer to char", rather than "array MISSING_SIZE of char". ...
    (comp.lang.c)
  • Re: how to return an array from function
    ... > I want to know a simple program of return array from function? ... ** Allocate space to hold _size_ ints, return pointer to ... void newa2 (size_t size, int **ap) ...
    (comp.lang.c)
  • Re: why cannot assign to function call
    ... hypothetical C-like languages, ... sizeof business would still indicate that a pointer was being passed. ... talk about variables of an array type. ... the earlier version of the standard didn't have numbered ...
    (comp.lang.python)
  • Re: embedded questions!!!
    ... >> both allocate space for a modifiable string. ... >> pointer to that string. ... An array is a group of contiguously allocated objects of the same ...
    (comp.arch.embedded)
  • Re: multi dimensional arrays as one dimension array
    ... please - where does the standard say that such a conversion ... Pointer conversion yields a pointer to the same object as ... exist only where there are array declarations. ...
    (comp.lang.c)