Hi,
Its strange that you should say this. In my opinion it goes like
this :
The identifier denoting the array, can in certain contexts decay
into a pointer to the first element of the array.
However what could be wrong with returning a pointer to an array...
it wud still remain a pointer to the array and not decay into a
pointer to a pointer. Remember, the decay rule is applicable only
once.
So let's say we have
<excerpt>
int a[10];
int (*p)[10];
p=&a;
return(p);
</excerpt>
Why would you say that this would not return a pointer to an array?
Theres no reason it should not.
You are correct. Any type "array of T" decays into a type of "pointer
to T" when used as a value. However this does not mean that "array of
array of T" decays into "pointer to pointer of T", neither does it
mean that "pointer to array of T" decays into "pointer to pointer to
T".
Here's some detail. It is always true that if arr is of type "array of
T", then arr[1] begins exactly sizeof(T) bytes after arr[0]. Let's say
"T" is "array of 10 chars" and sizeof(char *) is 4. This means that
arr[1] begins exactly 10 bytes after arr[0]. However if, when arr is
used as a value, its type would decay to "pointer to pointer to char",
then arr[1] would begin exactly 4 bytes after arr[0]. It can't be both
10 and 4, now can it?
--
/-- Joona Palaste (
[email protected]) ------------- Finland --------\
\--
http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The obvious mathematical breakthrough would be development of an easy way to
factor large prime numbers."
- Bill Gates