3 ms·
Why would that be? You don't cast the result of malloc in C. It's wholly unnecessary, adds clutter to the code, and potentially hides an error if you forgot to
by EpicEng 8y ago
Why would that be? You don't cast the result of malloc in C. It's wholly unnecessary, adds clutter to the code, and potentially hides an error if you forgot to include stdlib.h.
So why would that be "the preferred way"? I've been writing C for some time and no one who knows C casts the return value of malloc.
- optymizer 8y agoThe parent comment was referring to the usage of sizeof(). Also, the fact that they cast the result of malloc makes me think they were using a C++ compiler, which will complain that there's no cast.
- blattimwind 8y agoIf you're compiling for C++, you should be using static_cast<> instead.
- EpicEng 8y ago>The parent comment was referring to the usage of sizeof(). Ah ok, makes more sense in re-reading now. I was lazy and went off of a child comment. >Also, the fact that they cast the result of malloc makes me think they were using a C++ compiler, which will complain that there's no cast. Definitely could be that.