[LEAPSECS] Lets get REAL about time.

Paul J. Ste. Marie paul_j at ste-marie.org
Fri Jan 27 11:30:25 EST 2012


On 1/22/2012 7:42 AM, Clive D.W. Feather wrote:

> #define timespecsub(vvp, uvp) \

> ((vvp)->tv_sec -= (uvp)->tv_sec, \

> (vvp)->tv_nsec -= (uvp)->tv_nsec, \

> ((vvp)->tv_nsec< 0) \

> ? ((vvp)->tv_sec--, (vvp)->tv_nsec += 1000000000) \

> : (void) 0)

>

> This has the advantage of being usable wherever a function can appear.


Not really. For example &timespecsub doesn't work. The do-while kludge
can at least protect the arguments, eg:

#define timespecsub(vvp1, uvp1) \
do { \
const struct timespec *vvp = vvp1; \
const struct timespec *uvp = uvp1; \
(vvp)->tv_sec -= (uvp)->tv_sec; \
(vvp)->tv_sec -= (uvp)->tv_sec; \
(vvp)->tv_sec -= (uvp)->tv_sec; \
(vvp)->tv_nsec -= (uvp)->tv_nsec; \
if ((vvp)->tv_nsec < 0) { \
(vvp)->tv_sec--; \
(vvp)->tv_nsec += 1000000000; \
} \
} while (0)

and aside from not having an address otherwise behaves like a void function.

--
--Paul



More information about the LEAPSECS mailing list