Originally Posted by qwerty4061
Originally Posted by Doc CPU
For me, a type cast on the result of malloc() looks more like an attempt of obfuscation. I avoid it for the sake of clarity.
I disagree with you on this. I think it improves readability
I think it doesn't. Usually, you need to use a type cast to cheat on the compiler's type checking - that is, if you want to do something that isn't entirely "legal" in terms of the logics of C.
Assigning a pointer to a freshly allocated chunk of memory, however, is absolutely legal. There's no need for cheating here.
But as soon as I see an explicit type cast in an expression, there's an alarm bell in my programmer's mind: "Watch out! There's something strange, something unusual!" And then I look twice and see: Oh, just an exaggeration in being explicit.
And that doesn't improve readability, it ruins it. And it reduces your sensitivity for really complex expressions that would really deserve special attention.
That's my conviction.
[X] Doc CPU