This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2.2][BZ #12515] Improve precision of clock function
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Rich Felker <dalias at aerifal dot cx>
- Cc: Siddhesh Poyarekar <siddhesh at redhat dot com>, libc-alpha at sourceware dot org
- Date: Wed, 12 Jun 2013 14:48:32 -0700
- Subject: Re: [PATCH v2.2][BZ #12515] Improve precision of clock function
- References: <519B9A09 dot 6030305 at cs dot ucla dot edu> <20130521161441 dot GQ8927 at spoyarek dot pnq dot redhat dot com> <20130603092604 dot GL2145 at spoyarek dot pnq dot redhat dot com> <20130610083821 dot GD1570 at spoyarek dot pnq dot redhat dot com> <51B66522 dot 1060008 at cs dot ucla dot edu> <20130611135422 dot GK8010 at spoyarek dot pnq dot redhat dot com> <20130611171952 dot EB3CF2C0A2 at topped-with-meat dot com> <20130612050307 dot GU8010 at spoyarek dot pnq dot redhat dot com> <20130612173819 dot 67B272C07E at topped-with-meat dot com> <20130612192718 dot GH19582 at spoyarek dot pnq dot redhat dot com> <20130612202701 dot GA29800 at brightrain dot aerifal dot cx>
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);