signal() always returns a callable function pointer? 
Author Message
 signal() always returns a callable function pointer?

Is it always safe to do this?

        old_handler = signal(SIGFOO, my_handler);
        old_handler();    /* <---- suspicious... */

The reason I'm suspicious is that I cheated and looked at some
header files, and found that SIG_IGN and SIG_DFL are *not* pointers
to actual functions. Instead, they are typecasted ints!


Louisiana Tech University BSEE/Sr  * All rights reserved. No warranty, etc

Fri, 16 Aug 1996 13:37:15 GMT  
 signal() always returns a callable function pointer?


>Is it always safe to do this?
>    old_handler = signal(SIGFOO, my_handler);
>    old_handler();    /* <---- suspicious... */

        The standard doesn't guarantee that; the reasons must be more or
less the ones that you state - prior art was that way.  The return value
of the signal function is to be used only for resetting the signal status
back to its previous state.

        A signal can be generated by a program only by calling the raise
function.  Such signals, however, work more or less like ordinary function
calls - thus it is permissible to call the standard library functions from a
signal occurring because of a raise function call.

/* Teach me to feel another's woe,
   To hide the fault I see;
   That mercy I to others show,
   That mercy show to me                - Alexander Pope */

/* Ajoy Krishnan T,
   Senior S/W Engineer., Hughes Software Systems,
   New Delhi - 19, India.

Fri, 16 Aug 1996 21:27:00 GMT  
 signal() always returns a callable function pointer?


>Is it always safe to do this?

>    ...
>    old_handler = signal(SIGFOO, my_handler);
>    ...
>    old_handler();    /* <---- suspicious... */

ISO 7.7:

   The macros defined are SIG_DFL, SIG_ERR, SIG_IGN which expand to
   constant expressions with distinct values that have type compatible
   with the second argument to and the return value of the signal
   function, and whose value compares unequal to the address of any
   declarable function.

So, provided your implementation defines suitable sematics for casting
integer constants to pointers and obeys certain a suitable linkage
convention, defining these macros as suitable cast integers is
perfectly valid.  Consequently, here is no guarantee that either of
these are pointers to real functions.

Alan Watson                        | Users of double-precision complex will  

Department of Astronomy            |                     --  Brian Kernighan
University of Wisconsin -- Madison |                                        

Sat, 17 Aug 1996 02:42:13 GMT  
 [ 3 post ] 

 Relevant Pages 

1. Question about signal()/pointers to functions that return pointers to functions

2. Pointer to function returning pointer to function returning...

3. return a pointer, always get 0000 as its segment

4. GIT always return 0 to the registered interface pointer

5. Can function returning pointer return negative integers?

6. Why InetIsOffline function always return FALSE?

7. CInternetSession QueryOption function always return true.

8. Returning Pointer To Pointer From Function

9. Function returning a function-pointer - how to prototype ?

10. Declaring static function returning pointer to extern function

11. About function that returns function pointer

12. Function returning pointers to functions (repost)


Powered by phpBB® Forum Software