Mail Archives: djgpp/2000/06/10/02:58:31
On 8 Jun 2000 10:24:22 GMT, Hans-Bernhard Broeker
<broeker AT physik DOT rwth-aachen DOT de> ate too many hallucinogenic mushrooms
and wrote:
>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.
Even better to use C++. Even if you don't use many of its features,
the standard library algorithms include sorts that have a nicer, type
safe way to specify a comparison function (using templates) and there
is generally stronger type checking.
C++ does require a void * be cast to another pointer type, or produce
a warning or maybe an error. So you have to cast a malloc return
value, which is a hint that maybe in a C++ program you should be using
new :-)
--
Any sufficiently advanced magic is indistinguishable from
an Allegro-using C++ program compiled with gcc.
- Raw text -