Richard said:
I have the following source code. It seems wierd to me why gca's value
cannot be reassigned. It's afterall a pointer and has a pointer value.
char gca[7];
That's not a pointer.
No, it's not even a "constant pointer".
RTFFAQFFS: <
http://c-faq.com/aryptr/index.html>.
Richard
Arrays are ``second-class citizens'' in C; one upshot of this prejudice
is that you cannot assign to them.
Indeed.
Well, I guess it's just reiterating my confusion. Why should arrays be
second class citizens? gca does have a memory location. The value of
gca has to be stored in memory so gca[0] etc can be accessed.
Arrays are second class citizens because that's the way they are defined.
gca does have a memory location, in the same way that an int variable
has a memory location. The int variable's memory location is known to
the compiler, but it is not stored in memory.
You are attempting to do the equivalent of this:
int foo;
int bar;
&foo = &bar; /* constraint violation */
Why can't you assign to the address of foo? Foo has a (fixed) memory
location, but &foo does not have its own memory location. It's just a
value that the compiler calculated for you.
Similarly, the array gca has a memory location but its location is not
stored in memory; it is fixed. You cannot change its address.