Re: How to read data ?

From: pete (pfiland_at_mindspring.com)
Date: 11/19/04


Date: Fri, 19 Nov 2004 12:45:38 GMT

Mark McIntyre wrote:
 
> No decent /C/ programming book will cast malloc.

Er um..., and if they do, they post an errata page.

http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html

42(§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


Relevant Pages

  • Re: C99 Question
    ... ("the proper method is to declare ... ... then explicitly coerce") ... fails to be declared as returning void *. ... The explicit cast can cover up an unintended error. ...
    (comp.lang.c)
  • Re: faq & casting malloc()
    ... The remark about casting the return value ... explicitly coerce") needs to be rewritten. ... fails to be declared as returning void *. ... The explicit cast can cover up an unintended error. ...
    (comp.lang.c)
  • Re: Inconsistent Program Results
    ... void rdinput; ... you need to test that restrict is not NULL before ... Don't cast the result of malloc(). ...
    (comp.lang.c)
  • Re: OT: Memory profiling on Linux
    ... I need to profile my milter daemon on linux. ... Then you can go through the allocation log, and any allocations that don't ... #define MALLOC malloc ... void *mymalloc ...
    (comp.lang.c)
  • Re: Cipher Lab / Syntech
    ... this is not Google Groups. ... The "simple" library without malloc is needed because I was told ... void foo { ... int dprintf { ...
    (comp.lang.c)