[PATCH v2.2][BZ #12515] Improve precision of clock function
Paul Eggert
eggert@cs.ucla.edu
Wed Jun 12 21:48:00 GMT 2013
On 06/12/13 13:27, Rich Felker wrote:
> There is a hidden
> assumption here that CLOCKS_PER_SEC evenly divides 1000000000.
Rather than merely adding a comment to document the assumption,
it'd be better to check the assumption at compile-time,
so that compilation fails if there's a screwup.
We could do this by using gnulib's verify.h and then putting this into clock.c:
#include <verify.h>
verify (1000000000 % CLOCKS_PER_SEC == 0);
Or if we'd rather not use gnulib's verify.h we could approximate
its implementation of 'verify'; something like this:
/* Verify that R is true, at compile-time. */
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L
# define verify(r) _Static_assert (r, "__verify (" #r ")")
#else
# define verify(r) \
extern char __verify[sizeof (struct { unsigned int i: (r) ? 1 : -1; })]
#endif
verify (1000000000 % CLOCKS_PER_SEC == 0);
More information about the Libc-alpha
mailing list