"JS" <sf****@asdas.com> writes:
"Lawrence Kirby" <lk****@netactive.co.uk> skrev i en meddelelse
news:pa****************************@netactive.co.u k... On Wed, 16 Mar 2005 15:52:23 +0100, JS wrote:
> In K&R I have found this:
>
> static char allocbuf[ALLOCSIZE];
> static char *allocp = allocbuf;
[snip] allocp = allocbuf;
it is NOT equivalent to
*allocp = allocbuf;
In the book they say that:
static char *allocp = allocbuf;
is equivalent with:
static char *allocp = &allocbuf[0];
Yes.
with I assume is also equivalent with:
static char allocp = allocbuf;
No, that's not equivalent at all. The first two declarations declare
allocp as a variable of type pointer-to-char. The last declares is as
a variable of type char, a completely different type.
The C FAQ is at <http://www.eskimo.com/~scs/C-faq/faq.html>.
I recommend section 6, which discusses arrays and pointers. (Actually
I recommend the whole thing, but section 6 is most relevant to what
you're asking about.)
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.