Message-Id: <2.2.32.19970303150304.00689f6c@mailhost> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Mon, 03 Mar 1997 13:03:04 -0200 To: djgpp AT delorie DOT com From: Eyal Ben-David Subject: Re: quick malloc question >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. > `malloc' returns void* while p can be of any pointer type. You are actually casting from (void*) to (char*). In C it is not a problem, the compiler does the conversion for you with or without warnings (depends on the compiler and warning level). In C++ it is a compilation error so you must explicitly cast from one pointer type to another (except when the target type is void*). Eyal.