break, continue, return, goto (net.religion.c)
Joseph S. D. Yao
jsdy at hadron.UUCP
Thu Nov 14 15:49:40 AEST 1985
In article <521 at busch.UUCP> dcm at busch.UUCP (Craig Miller) writes:
> Today's C question: how come C won't let you increment a global,
> static or automatic array name, but will let you increment an array
> name that's a function argument? Film at 11.
Craig, I hope you're not serious. You've been around this newsgroup
(I thought) since the last time I wrote >= 100 ll on this subject.
For those who weren't, the problem is that when one seems to pass
an array as an argument in C:
char name[128];
...
foofunc(name);
...
foofunc(str)
char str[];
{
one isn't really. This is one case where C violates the Rule of
saying what you mean. For historical reasons (see diatribe in
archives), what is passed is the address of the first element of
the array -- a pointer instead of the array! This is one reason
(of two basic ones) that there is the confusing statement somewhere
in K&R that pointers and array addresses are treated identically.
In this case, a correct declaration of str would be:
char *str;
but I may just want to emphasize the array-ness of it [*sigh*].
In any case,
an array is a set of values at a fixed location. we
cannot change the value of that fixed location (name++)
any more than we can change any other fixed value
(foofunc++ or foofunc()++) or constant (1++ ?????).
a pointer is a single pointer-size (not necessarily word)
location in memory in which can be placed an address, such
as the address of the beginning of that array. The pointer
can be changed: in particular, it can be incremented and
decremented (str++).
More concisely:
a pointer name represents an l-value.
an array name doesn't.
--
Joe Yao hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}
More information about the Comp.lang.c
mailing list