gwowen said:
So if I use a C99-mode compiler (or -Wmissing-prototypes or
equivalent), the major (sole?) reason for not casting vanishes, right?
No.
First of all, C99 removed implicit int, but it still doesn't require
prototypes. That's probably not relevant in this case, since you
still need a visible declaration that specifies the return type.
The real reason not to cast the result of malloc is that *the cast
has no benefit* (except in the rare case where you want to compile
the same code as C and as C++).
I can write:
ptr = malloc(count * sizeof *ptr);
The code is perfectly clear to anyone who knows the language well
enough, and it works. Adding a cast, in the best case, simply adds
information that the compiler already knows. Why bother?
Would you use a cast for this?
float x = (float)sqrt(2.0);
I wouldn't, because it's unnecessary.