| Alex Fraser 2006-03-19, 12:02 pm |
| "hierarchical_polymorphist" <hierarchicalpolymorphist@gmail.com> wrote in
message news:1142715181.503447.321040@g10g2000cwb.googlegroups.com...
> One more thing, I've seen many after many codes and books that actually
> cast the result of malloc(). (Apart from the point Alex made that
> failure to include <stdlib.h> will cause a compiler warning, but I
> actually included that in my original program. Well...in my case, this
> step is unnecessary, but in general, why isn't it a good practice to
> cast the return value from malloc?)
The main reason (in my opinion) is the undefined behaviour due to the
missing declaration. There is also the simple fact that the cast is not
necessary: you waste time typing it, and anyone who reads the code wastes
time processing the redundant cast.
Google turned up the following link, which from a quick scan looks worth a
read: http://www.cpax.org.uk/prg/writings/casting.php
Alex
|