Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!purdue!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: void * and pointers to functions Message-ID: <25720@mimsy.umd.edu> Date: 26 Jul 90 05:25:09 GMT References: <1990Jul25.213257.7872@mdivax1.uucp> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 30 In article <1990Jul25.213257.7872@mdivax1.uucp> Jim Robinson writes: >It is my understanding of K&R I C that a variable of type char * may only >contain a pointer to a data object ... Correct (among other possibilities is, e.g., the Univac compiler in which object pointers are one or two words but function pointers are nine words long). >After reading the relevant parts of K&R II it would appear that a variable of >type void * may legally contain a pointer to a function as well as a >pointer to any of the various data types. Is this correct? No; the old restriction continues to apply. What *is* guaranteed in New (ANSI) C is that all function pointers can be stored in all other function pointers. That is, given an arbitrary pair of types T1 and T2, both of which are some kind of `pointer to function returning ...', one can legally write: T1 p1; T2 p2; ... (set p2 to point to some actual function) p1 = (T1)p2; ... (*(T2 *)p1)(args); Note the final cast back to T2 before the call---without this the compiler is not obliged to generate correct code. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris