Re: __TIME_MIN/__TIME_MAX
From: Bruce Evans (bde_at_zeta.org.au)
Date: 11/15/03
- Previous message: Garance A Drosihn: "Re: 64-bit time_t on sparc64, epilogue(?)"
- In reply to: Jacques Vidrine: "Re: __TIME_MIN/__TIME_MAX"
- Next in thread: Jacques Vidrine: "Re: __TIME_MIN/__TIME_MAX"
- Reply: Jacques Vidrine: "Re: __TIME_MIN/__TIME_MAX"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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"
- Previous message: Garance A Drosihn: "Re: 64-bit time_t on sparc64, epilogue(?)"
- In reply to: Jacques Vidrine: "Re: __TIME_MIN/__TIME_MAX"
- Next in thread: Jacques Vidrine: "Re: __TIME_MIN/__TIME_MAX"
- Reply: Jacques Vidrine: "Re: __TIME_MIN/__TIME_MAX"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
- Re: Using dlls
... >:> I am probably doing something very stupid indeed, ... >:> gently
tell me what it is I'd be very grateful! ... that IMPLIB would do this, ...
I had to take an educated guess what the utility was called in GCC, ... (comp.os.os2.programmer.misc) - Re: Vexing GCC warnings: "assignment discards qualifiers from pointer target type"
... snip ... ... > GCC probably realizes that and tries to prevent you
from doing ... > something stupid by warning about returning a string literal
as ... (comp.lang.c) - Re: [git patches 1/2] warnings: attack valid cases spotted by warnings
... (rofl, look at that mess: it was utterly impractical, unrealistic and ... stupid
for gcc to go and UTFify the compiler output. ... I absolutely *detest* how gcc
does idiotic quoting just because you ... (Linux-Kernel) - Re: Smashing the Stack?
... >the real question is how did the gcc developers come to this solution? ...
it looks pretty stupid. ... for a 3 chars buffer the compiler ... (Vuln-Dev) - Re: [PATCH] Make hash.h usable in the kernel
... course for the unsafe cast. ... since allowing this is equivalent to allowing
casting away of const. ... Maybe gcc is allowing a loophole or just making no more
effort than the ... was only the warning for that cast which made hash.h unusable (the
original ... (freebsd-net)