On Sat, 15 Sep 2007 18:14:30 -0700, "Chris Thomasson"
<> wrote:
>
> http://c-faq.com/malloc/mallocnocast.html
>
Thanx. Though I don't buy in that "argument".
Consider:
#include <stdio.h>
int main(void)
{
char *p = (char *) malloc(10);
return 0;
}
At least lcc-win32 DOES warn you: "Missing prototype for 'malloc'.
Same with Pelles C: "Missing prototype for 'malloc'".
Same with gcc: "implicit declaration of function 'malloc'".
So _my_ "A:" is: There's NOTHING wrong with casting malloc's return
value. (But don't forget to include <stdlib.h>, man!)
Moreover: From the answer in the FAQ I deduce that the claim
"... in C you should not cast the result of malloc,
because doing that might introduce subtle errors [...]"
is simply wrong: It's not the usage of the cast (as such) which "might
introduce[s] subtle errors. Not including <stdlib.h> is what actually
might introduce subtle errors - but (as it seems) most modern
compilers would catch that lapse (and produce a warning).
K. H.
--
E-mail: info<at>simple-line<Punkt>de