(void *) ? /* again */

Kenneth L Moore yahoo at unix.cis.pitt.edu
Mon Jan 22 12:17:17 AEST 1990


In article <6200009 at ux1.cso.uiuc.edu> phil at ux1.cso.uiuc.edu writes:

=>I have read (but I'm not sure where, I think it was in H&S) that when you
=>have the type   (void *)  then its effectively matches any pointer.  For
=>instance, malloc is declared like:
=>
=>        void * malloc();
=>
=>and you should be able to use it like:
=>
=>        long * plong;
=>        plong = malloc( sizeof(long) );
=>

Have you tried to coerce the type with 
    
       plong = (long *) malloc(sizeof(long)); 

and no declaration of malloc? This way you can use malloc for several
different types of pointers in the same program.

-- 
I don't yell and I don't tell and I'm grateful as hell: Benny Hill



More information about the Comp.lang.c mailing list