Why can you cast an array to a pointer?
Steven Schveighoffer
schveiguy at gmail.com
Thu May 11 20:44:36 UTC 2023
Why is this still possible?
```d
int[] arr = new int[50];
auto ptr = cast(int *)arr;
```
1. casting is a blunt instrument, and can cause some really bad problems
on code eveolution.
2. Literally easier to do arr.ptr instead of cast(T*)arr
Can we get rid of this? If you need the cast mechanism, and you really
mean it, you can do `cast(T*)arr.ptr`
The biggest problem is that people using C API which take `char *`
instead of `string` or whatnot, use `cast` and come to discord/etc with
the inevitable problems this causes.
-Steve
More information about the Digitalmars-d
mailing list