prev up next   top/contents search

comp.lang.c FAQ list · Question 4.13

Q: What's the total generic pointer type? My compiler complained when I tried to stuff function pointers into a void *.


A: There is no ``total generic pointer type.''

void *'s are only guaranteed to hold object (i.e. data) pointers; it is not portable to convert a function pointer to type void *. (On some machines, function addresses can be very large, bigger than any data pointers.)

It is guaranteed, however, that all function pointers can be interconverted, as long as they are converted back to an appropriate type before calling. Therefore, you can pick any function type (usually int (*)() or void (*)(), that is, pointer to function of unspecified arguments returning int or void) as a generic function pointer. When you need a place to hold object and function pointers interchangeably, the portable solution is to use a union of a void * and a generic function pointer (of whichever type you choose).

See also questions 1.22 and 5.8.

References: ISO Sec. 6.1.2.5, Sec. 6.2.2.3, Sec. 6.3.4
Rationale Sec. 3.2.2.3
H&S Sec. 5.3.3 p. 123


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North