News for hackers. Stuff that matters.
Re:Your code should be taken out back, lined up against a wa... by scott_s on Tuesday July 27, 2010 @02:34PM (#1552199)
C allows implict casting of void* to any other kind of pointer. Hence, you never need to cast the return from a malloc if you're storing it in a pointer.

C++, however, does not allow this. So, if for some reason you're calling malloc rather than new in C++, you need to cast.

Re:Your code should be taken out back, lined up against a wa... by sanderjd on Tuesday July 27, 2010 @03:28PM (#1552412)
You are not the poster who said "casting malloc's return is evil", so perhaps you don't agree with that statement, but I don't see how either of the points you make lead to the conclusion that it is "evil". You say that since void* is implicitly cast to all pointer types, you never need to explicitly cast it, but why would that make an explicit cast evil?
Re:Your code should be taken out back, lined up against a wa... by mfukar on Tuesday July 27, 2010 @04:01PM (#1552531)
An explicit cast of the result of malloc() can mask an error when you haven't included its proper definition in stdlib.h.
Re:Your code should be taken out back, lined up against a wa... by np3000 on Tuesday July 27, 2010 @03:57PM (#1552519)