Re: Problem with malloc

From: Chris Fogelklou (chris.fogelklou_at_comhem.se)
Date: 04/04/04


Date: Sun, 04 Apr 2004 17:25:47 GMT

Hi Richard,

> It doesn't. If the code works with the cast, it'll work without it, too.

I concede... I just checked and I don't actually have a compiler now that
craps out without the cast. I could swear that I have used one that would
fail without the cast, so I have just always casted... and never turned
back.

> The correct fix is to include it. Casting merely hides the problem instead
> of fixing it.

I have not disagreed with this, however, cast or no cast.

> And the correct fix is to give a prototype, by including <stdlib.h>

Ditto.



Relevant Pages

  • 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: about the array
    ... 3- If you cast to the wrong type by accident, ... are malloc and free. ... the compiler should issue a diagnostic - gcc ... unknown set of arguments, and return an int. ...
    (comp.lang.c)
  • Re: a case for multiple inheritance
    ... and overrides the write functions to change ... the compiler would optimize it so that the double function call would be ... private new void Foo ... The cast not much ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Copying an array slice (Was: Re: Difficulties with passing multi-dimensional arrays)
    ... <snip examples which got garbled, look upthread if needed, except> ... hence convertible w/o cast> ... > removes the warning. ... > compile under a standards-compliant compiler". ...
    (comp.lang.c)
  • Re: about the array
    ... I guess the bottom line is - if the cast isn't necessary, why do it, esp. ... the compiler should issue a diagnostic - gcc gives: ... it], and screw up, e.g., without the declaration, the compiler *should* ... maybe the int taken by the ...
    (comp.lang.c)