Re: faq & casting malloc()
From: tweak (xbwaichunasx_at_cox.net)
Date: 06/24/04
- Next message: E. Robert Tisdale: "Re: Is these functions C90 and/or C99 ?"
- Previous message: CBFalconer: "Re: Local scope, external linkage?"
- In reply to: pete: "Re: faq & casting malloc()"
- Next in thread: Darrell Grainger: "Re: faq & casting malloc()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 23 Jun 2004 17:38:46 -0700
pete wrote:
> tweak wrote:
>
>
>>Note: The only item I can find regarding casting
>> of malloc() is K&R2 pg. 142:
>
>
> Check the errata:
> http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html
>
> 142(§6.5, toward the end): The remark about casting the return value
> of malloc ("the proper method is to declare ... then
> explicitly coerce") needs to be rewritten. The example is correct
> and works, but the advice is debatable in the context of the
> 1988-1989 ANSI/ISO standards. It's not necessary
> (given that coercion of void * to ALMOSTANYTYPE * is automatic),
> and possibly harmful if malloc, or a proxy for it,
> fails to be declared as returning void *.
> The explicit cast can cover up an unintended error.
> On the other hand, pre-ANSI, the cast was necessary,
> and it is in C++ also.
>
Thanks.
I didn't know there was a errata from the book available since
it's pretty old.
Thanks Again,
Brian
P.S. Sorry about messing up my understanding of the syntax.
- Next message: E. Robert Tisdale: "Re: Is these functions C90 and/or C99 ?"
- Previous message: CBFalconer: "Re: Local scope, external linkage?"
- In reply to: pete: "Re: faq & casting malloc()"
- Next in thread: Darrell Grainger: "Re: faq & casting malloc()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|