With respect to C programming, I’m seeing several cases in example code where pointer assignments involve an explicit cast of the right side operand even when it already matches the type of the left side operand. Just one example:
void memcpy(u8int *dest, const u8int *src, u32int len)
{
const u8int *sp = (const u8int *)src;
u8int *dp = (u8int *)dest;
for(; len != 0; len--) *dp++ = *sp++;
}
Of course, the function is also declared correctly in a header file as:
void memcpy(u8int * dest, const u8int * src, u32int len);
The function already defines the variable “src” as type “const u8int *”, so why is it given an explicit cast when assigned to “sp” which is also of type “const u8int *”? The same goes for the assignment of “dest” to “dp”.
If you’re looking for a magical mysterious reason to do this, you’ll be disappointed. There’s no point to this type of explicit typecasting.
This was a style decision (and IMO a bad one) of the programmer. Typecasting has potential dangers (by “masking” important warnings) and making the code more complex to read… it should be reserved for situations where it’s needed. This is not one of them.