From: Brent A Ellingson Newsgroups: comp.os.msdos.djgpp Subject: Re: quick malloc question Date: Mon, 03 Mar 1997 09:00:08 -0600 Organization: North Dakota Higher Education Network Lines: 31 Message-ID: <331AE778.5019BE88@badlands.nodak.edu> References: <5fdn2o$mvl AT freenet-news DOT carleton DOT ca> NNTP-Posting-Host: cx03.sod.cc.ndsu.nodak.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Paul Derbyshire wrote: > > "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. > > -- Yes, ANSI C will allow a (void *) to be changed (promoted?) into a pointer of another type, making a cast on malloc unnecessary. However, C++ will NOT allow void pointers to be similarly promoted. So, the answer to your question is that yes, gcc will allow it, but no, g++ will not allow it (weellll.... both will likely allow it, but g++ will complain). Brent Ellingson bellings AT badlands