Re: faq & casting malloc()
From: pete (pfiland_at_mindspring.com)
Date: 06/23/04
- Next message: Ray Muforosky: "Getting window coordinates"
- Previous message: Emmanuel Delahaye: "Re: _matherr doesn't get invoked when sscanf is called."
- In reply to: tweak: "faq & casting malloc()"
- Next in thread: tweak: "Re: faq & casting malloc()"
- Reply: tweak: "Re: faq & casting malloc()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 23 Jun 2004 11:40:42 GMT
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.
-- pete
- Next message: Ray Muforosky: "Getting window coordinates"
- Previous message: Emmanuel Delahaye: "Re: _matherr doesn't get invoked when sscanf is called."
- In reply to: tweak: "faq & casting malloc()"
- Next in thread: tweak: "Re: faq & casting malloc()"
- Reply: tweak: "Re: faq & casting malloc()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|