Le 31/10/2011 21:25, Timon Gehr a écrit :
On 10/31/2011 08:34 PM, bearophile wrote:
I don't see the need to accept this cast, because we have said that D
arrays are not pointers, and allowing the array to pointer cast means
introducing/leaving an useless special case, and in practice this
special case is not useful because arrays have the ptr property:
extern(C) void foo(char* str);
foo(cast(char*)"hello");
struct Foo {
int* p;
size_t n;
}
void main() {
Foo f;
auto x = f.ptr; // OK
}
Actually compile error :o).
So I think cast(int*)a1 should be forbidden.
-1. I don't really see any point in disallowing it. It is an explicit
cast, not some kind of bug prone implicit behaviour.
Well, because the ptr property is done for that. Actually, D ABI says
that the struct representing the array begins with length, then prt, so
the result isn't obvious from a low level perspective, which is kinda
sad when it goes to pointer manipulation.