:::: If you write malloc calls without casts, it's not because it's
:::: necessarily good programming practice but because your grandfather did.
::: But this is the one place where you're an idiot. A complete one.
:: That's an 'Ad Hominen' argument
: So is Plauger's assertion that those of us who disagree with him do so
: out of mere tradition.
Let me get this strait.
"Your lack of cast on malloc is traditional,
not a superior programming technique"
and
"You are an idiot"
are considered equally ad hominem. Good to know, good to know.
In the meanwhile, perhaps it isn't too horrible to point out that
adding the cast is duplicated information, (which you might think
is bad, but) which means static checking can diagnose some problems
otherwise difficult to find, and often having to do with writing
past the end of the malloced region, which is Bad, which makes
the apparently bad duplication Good.
To a certain extent, it's a matter of style, but I find that
putting assertions and "redundant" casts in code makes it
significantly more likely to work if it compiles.
Therefore I find this a *useful* style.
But that's just me, and I must say I sympathize with stating
the same type twice (once for size (which is sometimes implicit),
once for typechecking) in the same malloc call.
On the Nth hand, something like
p = malloc(sizeof *p);
is particularly handy, because you can change the type of p
without having to dive into the code everywhere. Better (IMO)
would be something like
p = (typeof *p)malloc(sizeof *p);
but I don't think that works.
Wayne Throop (e-mail address removed)
http://sheol.org/throopw