In article <11**********************@g47g2000cwa.googlegroups .com>,
<bn********@gmail.com> wrote:
Consider this:
int foo(int *a, int *b);
int (*bar)(void *, void *) = (void *)foo;
How legal - or illegal - is the typecast and are there real-world
situations where such code will cause trouble? I don't mean trouble
like in 'not compiling' but trouble like in 'crashing hard'.
Conversions between function pointers and object pointers (void * is a
special case of "object pointers") is undefined.
I'd expect to see problems on systems with segmented memory spaces -
code and data segments are the first obvious way of using features like
segmentation, and the conversions between pointers into the different
segments may or may not be lossy (and there's no requirement that the
implementation fake lossless conversions if the underlying conversion
is lossy like there would be with void * and object pointers).
Any function pointer can be converted into any other function pointer
type and back to its original type without losing necessary information,
so if you need a "generic function pointer type" casting to something like
void (*)(void) and back will work. Note that this doesn't have the "able
to convert without a cast" feature that void * has for object pointers.
dave
--
Dave Vandervies
dj******@csclub.uwaterloo.ca
There's a certain glee I get in the cockles of my heart every time I'm
reminded that there is no Flash plugin for my current platform.
--Eric Schwartz in the scary devil monastery