Mail Archives: djgpp/2000/06/08/06:30:52
Burgupalli Chaitanya <Chaitanya DOT Burgupalli AT fujixerox DOT co DOT jp> wrote:
> But there was a mailing list thread where in it was recomended that
> it is better not do that.
... and by coincidence, the problem you describe is _exactly_ the one
that is the key argument against malloc() casting. You've been
brushing a potential problem under the carpet by casting, which now
surfaces as you removed the casts:
> main.c:34: warning: assignment makes pointer from integer without a
> cast
This is the telltale sign of a forgotten #include <stdlib.h>. This
warning is somewhat serious, but with the cast in place, you wouldn't
have gotten it.
Casts between pointer types should be needed only *very* rarely, in a
properly written C program. Whenever you catch yourself writing one,
it's best to sit back and re-think your current strategy: chances are
you're just doing something silly or evil. About the only exceptions
from this rule are arguments to variadic functions (like printf())
that have to be casted to (void *), and casts back from void* to some
other type needed with calls through generalized function pointers
like the qsort() comparison function.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -