Re: Help with understanding this please



mdh wrote:
may I ask why you
have not cast the return from malloc to type "struct t_node n *).

In C, you *never* have to cast the return from malloc.


K&R devote quite a discussion to this on page 142.

This is an error in K&R which the authors have acknowledged. The discussion predates ANSI C.
.



Relevant Pages

  • Re: Linked List Library
    ... I don't recommend casting the return value of malloc: ... The cast is not required in ANSI C. ... When calling malloc(), I recommend using the sizeof operator on ... typedef struct ADCLIST_el ...
    (comp.lang.c)
  • Re: Looking for malloc() help
    ... struct item *stuff; ... Never ever cast the result from malloc() except you like to go into ... with mallocto avoid memory leaks. ...
    (comp.lang.c)
  • Re: why does this happen?
    ... you won't have to cast the output. ... > typedef struct ... Note that malloc() will return NULL if there were ... C++ Faq: http://www.parashift.com/c++-faq-lite C Faq: http://www.eskimo.com/~scs/c-faq/top.html alt.comp.lang.learn.c-c++ faq: ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Help with understanding this please
    ... Mark McIntyre said: ... have not cast the return from malloc to type "struct t_node n *). ... you *never* have to cast the return from malloc. ...
    (comp.lang.c)
  • Re: Help with understanding this please
    ... have not cast the return from malloc to type "struct t_node n *). ... you *never* have to cast the return from malloc. ... discussion predates ANSI C. ...
    (comp.lang.c)