Mail Archives: djgpp/1999/01/21/05:53:30
Matthew Conte wrote:
>
> [ e-mail address munged to thwart evil spambots - reply to group ]
>
> Edward Hill wrote in message <36A67204 DOT 5AF0 AT gec DOT nospam DOT com>...
> [...]
> > You shouldn't cast the return of malloc, it was orig used
> > to silence compiler warning messages but since ANSI/ISO and
> > the void * type it has become redundant and sometimes masks
> > errors.
:
: Is this true? It is bad practice to cast the return of malloc()?
I've
: never seen this discussed anywhere else.
:
: Thanks,
: Matt.
I refer you to the comp.lang.c FAQ section 7.7
7.7: Why does some code carefully cast the values returned by malloc
to the pointer type being allocated?
A: Before ANSI/ISO Standard C introduced the void * generic pointer
type, these casts were typically required to silence warnings
(and perhaps induce conversions) when assigning between
incompatible pointer types.
Under ANSI/ISO Standard C, these casts are no longer necessary,
and in fact modern practice discourages them, since they can
camouflage important warnings which would otherwise be generated
if malloc() happened not to be declared correctly; see question
7.6 above.
References: H&S Sec. 16.1 pp. 386-7.
- Raw text -