In article <09************************@no.email.shaw.ca>
kelvSYC <kelvSYC> writes:
I have a declaration of a pointer to an array of a struct as follows:
struct foo (*a)[];
And I have an array of a struct as follows:
struct foo b[];
However, a = &b returns an error (illegal assignment to constant).
Why is this? Is it because the dimensions to b are not defined?
If so, that would be a compiler bug. But I suspect the above is
not *quite* what you have (although "array of unknown size" *is*
not very useful, hence not used much, hence one should suspect
compilers might be buggy in this area).
GCC (under -ansi -pedantic) is perfectly happy with the following,
which is not proof, but is some evidence that it is OK:
% cat /tmp/t.c
struct foo;
struct foo (*a)[];
extern struct foo b[];
void f(void) {
a = &b;
}
% cc -ansi -pedantic -W -Wall -O -c t.c
%
The variable "a" has type "pointer to array ? of struct foo", where
"?" represents "unknown size". (Some prefer to write this as
"pointer to array of ? `struct foo's".) Note that there is absolutely
nothing you can do with the variable "a" that you could not do more
simply with another variable:
struct foo *a1 = *a;
Now you can replace any occurrence of (*a)[i] with a1[i], and any
occurrence of *a with plain a1. The only thing the pointer in "a"
would give you that a1 would not is the ability to write a[h][i]
for some integer h, but with the size of the arrays to which "a"
points unspecified, so the only valid value for "h" is an integer
constant zero: a[0][i], which is the same as (*a)[i].
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.