Re: embedded questions!!!
- From: "Richard Henry" <rphenry@xxxxxxxx>
- Date: Fri, 13 Jan 2006 10:50:47 -0800
"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.
.
- Follow-Ups:
- Re: embedded questions!!!
- From: Bob Stephens
- Re: embedded questions!!!
- References:
- Re: embedded questions!!!
- From: Rufus V. Smith
- Re: embedded questions!!!
- From: Chuck F.
- Re: embedded questions!!!
- From: John B
- Re: embedded questions!!!
- From: Richard Henry
- Re: embedded questions!!!
- From: Dave Hansen
- Re: embedded questions!!!
- Prev by Date: Re: Ulf, what of these new AVRs? :)
- Next by Date: Re: embedded questions!!!
- Previous by thread: Re: embedded questions!!!
- Next by thread: Re: embedded questions!!!
- Index(es):
Relevant Pages
|