Re: __TIME_MIN/__TIME_MAX

From: Bruce Evans (bde_at_zeta.org.au)
Date: 11/15/03

  • Next message: Jacques Vidrine: "Re: __TIME_MIN/__TIME_MAX"
    Date: Sat, 15 Nov 2003 19:17:10 +1100 (EST)
    To: Jacques Vidrine <nectar@FreeBSD.org>
    
    

    On Fri, 14 Nov 2003, Jacques Vidrine wrote:

    > Bruce Evans said the following on 11/14/03 6:54 PM:
    >
    > > I prefer the cast.
    >
    > Actually, so do I :-) MIN/MAX values won't work for removing some (IMHO
    > stupid) warnings emitted by GCC. So this kind of thing OK?
    >
    > long n;
    > time_t t;
    > errno = 0;
    > n = strtoul(...);
    > if (errno == ERANGE || (long)(t = n) != n)
    > /* out of range */;

    Not quite like that. strtoul() returns an unsigned long whose value may
    be lost by assigning it to a plain long. Mixtures of signed and unsigned
    types are tricky to handle as usual. Suppose we make n unsigned long
    and it has value ULONG_MAX, and time_t is long, then (t = n) == n,
    but t doesn't actually represent n (casting (t = n) to long or unsigned
    long doesn't help). So it seems to be necessary to be aware that time_t
    is signed and either use strtol() initially or check that t >= 0 if
    n is unsigned long. If time_t is actually signed then we may get a GCC
    warning for this check...

    Bruce
    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"


  • Next message: Jacques Vidrine: "Re: __TIME_MIN/__TIME_MAX"

    Relevant Pages