Kaz Kylheku <kkylheku@gmail .comwrote:
Casting malloc is just fine.
juice carry a dangerous substance sign.
In fact, it's useful in a C compiler to have C++-style type checking
for void *: that is to say, implicit conversions from void * to some
other pointer type being diagnosed.
for void *: that is to say, implicit conversions from void * to some
other pointer type being diagnosed.
Getting spurious warnings for them is a bother, and makes you ignore
real warnings. Casting away those spurious warnings is also a bother,
and makes you a. ignore real casts and b. cast away other, important,
warnings.
The rationale for /not/ casting malloc is outdated, based on the idea
that compilers allow functions to be called without a prior
declaration, without issuing a diagnostic.
that compilers allow functions to be called without a prior
declaration, without issuing a diagnostic.
Code reviewers have to look not only for bugs, but for adherence to
coding conventions (and be pedantic about that just as much as
language issues).
coding conventions (and be pedantic about that just as much as
language issues).
Spurious casts are dangerous. Not always to the program - but nearly
always to the program_mer_. That's the real reason to avoid them. Casts
should make you sit up and think "Hey, a cast! What is going on here?",
not "Oh, *yawn* another cast, must be more C++-avoidance hackery".
Richard
Leave a comment: