www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/03/12:02:44

From: Brent A Ellingson <bellings AT badlands DOT nodak DOT edu>
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: <B0000041587 AT datasoft DOT datasoft DOT com DOT br> <5fdn2o$mvl AT freenet-news DOT carleton DOT ca>
NNTP-Posting-Host: cx03.sod.cc.ndsu.nodak.edu
Mime-Version: 1.0
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

- Raw text -


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