www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/03/16:48:16

To: ao950 AT FreeNet DOT Carleton DOT CA
Cc: djgpp AT delorie DOT com
Subject: Re: quick malloc question
Message-ID: <19970303.162642.7191.0.fwec@juno.com>
References: <B0000041587 AT datasoft DOT datasoft DOT com DOT br>
From: fwec AT juno DOT com (Mark T Logan)
Date: Mon, 03 Mar 1997 16:30:10 EST

On 3 Mar 1997 05:20:24 GMT ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
writes:
>
>"Cristovao Braga" (cbraga AT datasoft DOT com DOT br) writes:
>> char *p;
>> 
>> main ()
>>    {
>>       p = (char *) malloc (5 * 1024 * 1024);
>>    }
>
>Why the HELL do people keep writing things like (char 
>*)malloc(x)????????
>
>GCC, and to my knowledge other compilers, allow any pointer to be 
>assigned
>to a variable of type void * and conversely allow any variable of type 
>void
>* to be assigned to any pointer, without casts.

This is true, almost any compiler will allow you to do it without cast.
However, almost any compiler will also give you a warning about it.
Most people like to keep their code as warning free as possible, so
they cast pointers.

-Fwec

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019