Mail Archives: djgpp/1995/09/13/22:55:34
>>>>> "Malcolm" == Malcolm Taylor <empty AT sans DOT vuw DOT ac DOT nz> writes:
Malcolm> It will work, casting a function pointer is allowed (just
Malcolm> another type of pointer, nothing special).
In most C implementations, yes. But my understanding is that some C
implementations can make function pointers be more complicated types
which cannot be cast to simple pointers; for example, a "function
pointer" might also include information about argument types.
Consequently, the language spec allows certain types of casts to be
forbidden. From Harbison & Steele:
ANSI C introduces the type void * as a "generic pointer." It
has the same representation as type char * for compatibility
with older implementations, but the language treats it
differently. Generic pointers cannot be dereferenced with the
* or subscripting operators. Any pointer to an object or
incomplete type (but _not_ to a function type) can be
converted to type void * and back without change.
[emphasis in original]
I was just making a technical point about one of the many ways my hack
isn't ANSI compliant.
Maclolm> There are a few other things to watch for. Make sure you
Malcolm> do not compile with optimizations (esp. not -O3) as these
Malcolm> can shift code about.
To the best of my knowledge, gcc won't shift them about unless those
functions are static. Obviously it's allowed to do so, but I don't
think it does. But since some future gcc implementation might, an
"assert" is probably a good idea.
-Mat
- Raw text -