Re: __TIME_MIN/__TIME_MAX

From: Jacques Vidrine (nectar_at_freebsd.org)
Date: 11/15/03

  • Next message: Harti Brandt: "Re: 64-bit time_t on sparc64, epilogue(?)"
    Date: Sat, 15 Nov 2003 07:04:04 -0600
    To: Bruce Evans <bde@zeta.org.au>
    
    

    Bruce Evans said the following on 11/15/03 2:17 AM:
    > On Fri, 14 Nov 2003, Jacques Vidrine wrote:
    >> 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...

    Doh, sorry, that's a typo. I meant strtol (which is what is currently
    used in the relevant portion of libc--- strptime.c, BTW). Negative
    values must be allowed here.

    Cheers,

    -- 
    Jacques Vidrine   NTT/Verio SME      FreeBSD UNIX       Heimdal
    nectar@celabo.org jvidrine@verio.net nectar@freebsd.org nectar@kth.se
    _______________________________________________
    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: Harti Brandt: "Re: 64-bit time_t on sparc64, epilogue(?)"

    Relevant Pages

    • Re: array of structures.
      ... strtol is for long (can also be used for int, ... short and signed char), strtoul is for unsigned long (also for unsigned ... wrong with the conversion, point you to the place where the conversion ...
      (comp.lang.c)
    • Re: [comp.lang.c.moderated] Re: reading in lines from a file that contain large (and unknown)
      ... After cursorily checking 7.19.6.2 "The fscanf function", ... referred 7.20.1.4 "The strtol, strtoll, strtoul, and strtoull ... functions", then the referred 6.4.4.1 "Integer constants", I think ...
      (comp.lang.c.moderated)
    • Re: scanning string for ![0..9]
      ... > This will only count leading non-digits. ... > A somewhat twisted method is to use strtol or strtoul in combination ... the conversion will detect and ...
      (comp.lang.c)
    • Re: strtoul bug (was Fibonacci number)
      ... "Richard Bos" wrote in message ... >> suffix that is interpreted as a negative sign by strtol(), ... >> recognized by strtoul(). ... OK, the suffix is recognized by strtoul, too, but doesn't affect its ...
      (comp.lang.c)
    • Re: convert string to size_t
      ... There is strtol and strtoul in C90, ... conversion don't capture errors in values that would ... Your data may never be less that zero, ...
      (comp.lang.c)