This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [ping2][PATCH v2][BZ #12515] Improve precision of clock function
- From: Rich Felker <dalias at aerifal dot cx>
- To: Paul Eggert <eggert at cs dot ucla dot edu>
- Cc: Siddhesh Poyarekar <siddhesh at redhat dot com>, libc-alpha at sourceware dot org
- Date: Tue, 11 Jun 2013 11:11:26 -0400
- Subject: Re: [ping2][PATCH v2][BZ #12515] Improve precision of clock function
- References: <20130521145611 dot GM8927 at spoyarek dot pnq dot redhat dot com> <20130521151839 dot GA18430 at domone dot kolej dot mff dot cuni dot cz> <20130521153442 dot GO8927 at spoyarek dot pnq dot redhat dot com> <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> <20130611014028 dot GU29800 at brightrain dot aerifal dot cx> <51B6BCF0 dot 9000207 at cs dot ucla dot edu>
On Mon, Jun 10, 2013 at 11:00:16PM -0700, Paul Eggert wrote:
> On 06/10/2013 06:40 PM, Rich Felker wrote:
> > First, to make the code work as-is
> > with the wrapping behavior, the values should just be converted to the
> > appropriate unsigned types so that the wrapping is well-defined, then
> > converted, either via a cast or implicitly, back to the right type.
>
> That's more work and harder to understand and more
> error-prone than the pragma. For one thing, there's
I disagree. Having to be aware of an obscure GCC feature, which many
readers would have to look up in the manual to understand, is a lot
less understandable than unsigned arithmetic (which anybody who knows
C should know).
> no simple way to determine the "appropriate
> unsigned type". And why bother? The code is designed
> to be compiled by GCC, so the pragma should suffice.
There are only two cases, either it's unsigned long or unsigned long
long. Which to use depends on the size of time_t.
> > This conversion takes place in an implementation-defined way
>
> Which is another reason to prefer the pragma.
Except that the latter is the same for all implementations.
Rich