Kenny McCormack wrote:
[...]
The point is that is you consider the following three commonly harped on
things in this NG:
1) char a[10]; x = a[10];
2) void main()
3) char *x = (char *) malloc(10);
The first is clearly an error. The 2nd probably, and the third, really not.
Yet all three are harped upon with equal vigor, by a bunch of freaks who
don't understand the concept of degree.
However, there are times when a newbie mentions that the reason
for putting the cast on malloc in the first place was to stop the
compiler from complaining about the int-to-pointer conversion.
While one might argue that the forgotten include won't happen in
"production code", the audience for clc is much wider than those
who write C for a living.
Yes, the cast is "harmless" if you have the proper #include. But,
it appears to be a relatively common newbie error to forget the
necessary #include, and they learned somewhere that you can "shut
up" the compiler by adding the cast, rather than by fixing the
root cause of the problem.
Now, I have an excuse for casting the return at times -- I learned
C in pre-void days, when the cast was necessary. Those days are
long gone, but old habits are hard to break. (Just try typing the
word "print" without a "f" magically appearing after it.)
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |
www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net |
www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:
[email protected]>