> On a related but separate note, is there any standard that guarantees
> that casting -1 to a function pointer type is reasonably portable?

This idiom is used widely enough to overload an argument so that it can
contain either a valid pointer, or convey a non-pointer state.

Take /usr/include/pthread.h, for example. It's not a function pointer,
but it's in the same ballpark:

GNU LIBC:

  #define PTHREAD_CANCELED ((void *)-1)

Solaris:

  #define PTHREAD_CANCELED (void *)-19

FreeBSD:

  #define PTHREAD_CANCELED ((void *) 1)

NetBSD:

  /*
   * POSIX 1003.1-2001, section 2.5.9.3: "The symbolic constant
   * PTHREAD_CANCELED expands to a constant expression of type (void *)
   * whose value matches no pointer to an object in memory nor the value
   * NULL."
   */
  #define PTHREAD_CANCELED ((void *) 1)

The UNIX call sigaction() does actually use such "invalid" casted function 
pointers:

  http://www.opengroup.org/onlinepubs/7990989775/xsh/sigaction.html

Where the function pointer sa_handler member of the struct sigaction can 
contain 
SIG_IGN and SIG_ERR. On one popular version of UNIX they are defined as:

  #define SIG_IGN (void(*)(int))1
  #define SIG_ERR (void(*)(int))-1



 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to