This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2.2][BZ #12515] Improve precision of clock function


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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]