Casting function pointer to void pointer 
Author Message
 Casting function pointer to void pointer

Is storing a function pointer in a void *variable kosher with the ANSI C
specification? I have had people tell me that this is forbidden by ANSI, but
compilers seem to accept it.

--
 --- Dale King



Sat, 15 Dec 2001 03:00:00 GMT  
 Casting function pointer to void pointer


Quote:
>Is storing a function pointer in a void *variable kosher with the ANSI C
>specification? I have had people tell me that this is forbidden by ANSI, but
>compilers seem to accept it.

No.  There is no requirement that a void* be large enough to hold
a function pointer and there are compilers in which it will not.
--
Michael M Rubenstein


Sun, 16 Dec 2001 03:00:00 GMT  
 Casting function pointer to void pointer


Quote:
> Is storing a function pointer in a void *variable kosher
> with the ANSI C specification?

 No, it's treif :)

Quote:
> I have had people tell me that this is forbidden by ANSI, but
> compilers seem to accept it.

   void * is guaranteed to hold any pointer to _object_ type.
On the other hand all function poiner do have the same representation,
so you can arbitrarily choose any one of them as a generic function
pointer (but, unfortunately, you must explicitely cast to/from it).

--
        Regards,
                Alex Krol
Disclaimer: I'm not speaking for Scitex Corporation Ltd

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Sun, 16 Dec 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. casting void pointer to be a pointer to a function

2. casting void pointer to be a pointer to a function

3. Casting function pointer to void*

4. Q: casting to a pointer to a function returning void

5. casting of struct element void pointer casting

6. pointers to functions and pointers to void.

7. Can void-pointers be casted to function-pointers?

8. How to use (pointer to function), and function and pointer to (pointer to function)

9. Casting a method pointer to a function pointer.

10. Pointer Functions and Pointers to Pointer Functions

11. Casting pinning pointer to void *

12. Casting from a void pointer

 

 
Powered by phpBB® Forum Software