You should never cast the return value of malloc()
, in C. Doing so is:
- Unnecessary, since
void *
is compatible with any other pointer type (except function pointers, but that doesn't apply here).
- Potentially dangerous, since it can hide an error (missing declaration of the function).
- Cluttering, casts are long and often hard to read, so it just makes the code uglier.
So: there are no benefits, at least three drawbacks, and thus it should be avoided.