Are you implying that ERT could be impersonating Mr. Plauger? That's a
very serious allegation; if you stand by it, you will need to back it
up. Even hinting at the possibility is possibly slanderous. Especially
in dealing with people of sometimes questionable standards (e.g. ERT's
well-documented quote-altering behavior) it is essential to keep to the
moral high ground.
The actual nature of C makes the cast redundant.
This is a bit vague for my taste. The cast is made superfluous by the
standard in typical-use cases, that's something more precise. However,
the standard (I'm talking about C99 now) also makes "return 0;" at the
end of main superfluous. Does that mean I'm going to follow suit? I
think not.
As to your use of the word "redundant": that is too strong for my taste.
malloc(50*sizeof(double))
and
(double *)malloc(50*sizeof(double))
have different types. Ergo, the cast has a function, with regard to this
expression, and it is not redundant.
The insertion of redundant casts -- not their omission --
> requires some sort of special justification. This is my point.
Yes. Over and over again, two justifications have been presented, by me
at least:
- making sure that your program is also conforming C++ (if you
want/need this for one reason or another).
- correcting the compiler's misconception about a pointer to an
allocated block of memory at the earliest possible convenience
(which means: prior to the pointer being used in any way,
for example, as the right-hand-side of an assignment).
For me, these are the justification.
Suppose "the C standard" is some sort of weighted average of C89 and
C99, the weights depending on the context of the discussion.
That sounds like a dangerous path to follow. The first problem is that
there exist no standards for weight values other than 0 and 1. The
second problem is that people can tune the weight to support their
opinion in any given situation. In essence, you're providing a knob that
one can turn to shift the goalposts.
As the
weight on C99 approaches 1.0, the stdlib.h argument approaches
negligibility. The argument that redundant casts are best
avoided retains its full force.
I object to your use of the word "redundant". It is fair to say that the
compiler will perform a conversion of the malloc result soon as a result
of the typical use pattern, where malloc() is used as the RHS of an
assignment, but that's something different entirely from saying the cast
is "redundant".
The Plauger1 argument that some
code may have to be compiled as C++ retains its orthogonality to
the issue of good C practice. The notion that "we really ought
to have to cast the malloc return and it's a shame we don't"
retains its irrelevance.
That's as explicit a restatement of the "because we can" argument as
they come. I whole-heartedly and sincerely disagree.
Best regards,
Sidney