Coercing C pointers to proper types is mainly for safety reasons and to ease cognitive load. A C pointer leaves out a lot of information; you won’t know if it’s a pointer to one or many elements, whether it’s optional, whether it’s a pointer to an array of a known length, whether it’s sentinel-terminated and so on, so as a compromise it acts as if it has all of those properties all at once. By explicitly coercing it to a correctly annotated type, the compiler will prevent you from doing incorrect things with it such as writing null
to a non-optional pointer or indexing into a single-element pointer beyond the first element.
4 Likes