The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 06-24-2009
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,937
Reducing the problem to its essence makes it easier to understand

Code:
#include <time.h>
#define BOGUSTID 9999

timer_t tid;
  
#if WANT_SEG_FAULT
   tid = (timer_t) BOGUSTID
#else
   int tval=BOGUSTID;
   tid = (timer_t) &tval;
#endif

The correct header is being included but an assumption is being made that tid is capable of storing a value as shown above. Generally this assumption is wrong as timer_t is specified to be an opaque type in POSIX.1. On most versions of GNU/Linux, timer_t is actually defined by

Code:
#define timer_t   void *

In your example you are trying to stuff 9999 into a void * - which is not on.

BTW, your workaround is defective also. tid is not being set to 9999 but to the address of tval.