Re: Help with understanding this please



On Aug 30, 4:21 pm, Mark McIntyre <markmcint...@xxxxxxxxxxxxxxxxxxx>
wrote:
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.

Thank you to all who have pointed this out...much appreciated.
.



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: problem with memcpy and pointers/arrays confusion - again
    ... this second method is known as an explicit conversion, or cast. ... The cast, in effect, tells the compiler: ... the malloc function. ... function taking a size_t as a parameter and returning a void pointer (i.e. ...
    (comp.lang.c)
  • Re: why is casting malloc a bad thing?
    ... In the compilers we used in the 1980s (including VAX ... compilers for IBM PCs), malloc() had type: ... Without the cast, you got ... and adds HUGE amounts of risk. ...
    (comp.lang.c)
  • Re: Casting the return value of malloc()...
    ... The major reason for not using superfluous casts, of which malloc() ... programmer's ability to treat a cast as a warning sign. ... then the compiler can catch type errors. ... The sizeof operator should never be followed immediately by '(' ...
    (comp.lang.c)
  • Re: Casting the return value of malloc()...
    ... The major reason for not using superfluous casts, of which malloc() ... programmer's ability to treat a cast as a warning sign. ... then the compiler can catch type errors. ... The sizeof operator should never be followed immediately by '(' because it is not a function. ...
    (comp.lang.c)