thoughts on &array
John Gilmore
gnu at sun.uucp
Wed Oct 10 18:26:02 AEST 1984
It seems like people (maybe me?) are still confused between pointers
and arrays. It has always seemed a botch that &array didn't work -- I
remember when I first learned C, I just concluded that it was a
broken language because &foo sometimes worked, sometimes failed, and
sometimes was ignored, depending on the type of foo.
Please check my understanding: A POINTER IS DIFFERENT FROM AN ARRAY.
If you say
char c1[10], *cp1;
then cp1 = c1; works, but if you say
char c2[10][5], **cp2;
cp2 = c2; it does not work; you have to say
char c2[10][5], *(cp3[5]);
(Those who can recall C precedence may be able to remove parens above.)
In the above, c1 is array of 10 char
cp1 pointer to char
c2 array of 10 array of 5 char
cp2 pointer to pointer to char
cp3 pointer to array of 5 char
(The difference between a pointer an an array is: dereferencing an
"array of N" leaves the address alone but changes the type to "N",
while dereferencing a "pointer to N" actually gets a new address out of
storage and types that address "N". Saying &c seems to create an
array, not a pointer, since *&c doesn't get any value out of storage.)
This has served as a rule of thumb for me for the last few years,
can a real language designer or compiler hacker tell me if I'm right?
It sounded to me like Steve Dyer was proposing that &c1 be
c1 array of 10 char
&c1 array of 1 array of 10 char
just like
c char
&c array of 1 char
It sounds good to me.
More information about the Comp.lang.c
mailing list