Mail Archives: djgpp/1997/03/03/12:02:44
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 -