From owner-freebsd-arch@FreeBSD.ORG Sat Nov 15 00:17:16 2003 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C5D4816A4CE; Sat, 15 Nov 2003 00:17:16 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 251C343F3F; Sat, 15 Nov 2003 00:17:15 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3p2/8.8.7) with ESMTP id TAA03482; Sat, 15 Nov 2003 19:17:11 +1100 Date: Sat, 15 Nov 2003 19:17:10 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Jacques Vidrine In-Reply-To: <3FB5B258.6010207@freebsd.org> Message-ID: <20031115190419.G1478@gamplex.bde.org> References: <20031114194119.GA94198@madman.celabo.org> <20031115114906.L11453@gamplex.bde.org> <3FB5B258.6010207@freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-arch@FreeBSD.org Subject: Re: __TIME_MIN/__TIME_MAX X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Nov 2003 08:17:16 -0000 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