Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uwvax!natasha.cs.wisc.edu!zvr From: zvr@natasha.cs.wisc.EDU (Alexios Zavras) Newsgroups: comp.unix.ultrix Subject: Re: looking for usleep() implementation for ULTRIX Message-ID: <8896@spool.cs.wisc.edu> Date: 19 Oct 89 02:13:17 GMT References: <5508@shlump.nac.dec.com> <5499@shlump.nac.dec.com> Sender: news@spool.cs.wisc.edu Reply-To: zvr@natasha.cs.wisc.EDU (Alexios Zavras) Organization: University of Wisconsin - Computer Sciences Department Lines: 55 In article <5508@shlump.nac.dec.com>, michaud@decvax.dec.com (Jeff Michaud) writes: > To make this really generic it should be defined as a function. As a > macro things like: > if( ... ) > usleep(...); > else > .... > because the "usleep(...);" is two statements, ie. a compound statement and > the null statement. This can be worked around if you use an explicit > compound statement around the "usleep(...);" while keeping your code > portable. The way to #define a macro as two or more statements, without having this problem is: #define macro(x) do { stmt1(x); stmt2(x); ... } while (0); So, the definition of usleep() looks like: /*=========================================================================*/ #ifdef ultrix #ifndef _TYPES_ #include #endif /* _TYPES_ */ #ifndef __XTIME__ #include #endif /* __XTIME__ */ #define usleep(usec) do \ { \ struct timeval usl_delay; \ usl_delay.tv_sec = (int) (usec) / 1000000; \ usl_delay.tv_usec = (int) (usec) % 1000000; \ (void) select(0,(fd_set *)0,(fd_set *)0,(fd_set *)0, &usl_delay);\ } while (0); #endif /* ultrix */ /*=========================================================================*/ > |Jeff Michaud michaud@decwrl.dec.com michaud@decvax.dec.com| -- zvr -- +-----------------------+ Alexios Zavras | Life is once, forever | zvr@cs.wisc.edu +-----------------H C-B-+ zavras@cs.wisc.edu Live from: Wisconsin: land of Orson Welles, Frank Lloyd Wright, Harry Houdini and Spencer Tracy (of Joe McCarthy, too, but we try to forget that)