From owner-freebsd-arch@FreeBSD.ORG Sun Nov 16 04:36:48 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 31EF816A4CE; Sun, 16 Nov 2003 04:36:48 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6C15343F93; Sun, 16 Nov 2003 04:36:46 -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 XAA04395; Sun, 16 Nov 2003 23:36:42 +1100 Date: Sun, 16 Nov 2003 23:36:41 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: "Jacques A. Vidrine" In-Reply-To: <20031116111212.GA55844@madman.celabo.org> Message-ID: <20031116231838.X1400@gamplex.bde.org> References: <20031114194119.GA94198@madman.celabo.org> <3FB6AA8F.37ED6D50@mindspring.com> <20031116111212.GA55844@madman.celabo.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: Sun, 16 Nov 2003 12:36:48 -0000 On Sun, 16 Nov 2003, Jacques A. Vidrine wrote: > On Sun, Nov 16, 2003 at 04:20:10AM -0600, Jacques A. Vidrine wrote: > > /* How can this be implemented correctly? */ > > int range_error(long n, time_t t) > > { > > return (long)(t = n) == n; > > } > > Hrmp. Because time_t is probably signed, technically this can cause > `undefined behavior' if the range of `long' is more than the range of > `time_t' (e.g. on alpha). *sigh* Actually, it's implementation-defined if time_t is integral (doesn't matter if it is signed or unsigned) (and the value is not representable). It's only undefined if time_t is a floating type. > All I really want to do is correct a parsing bug and at the same time > eliminate a warning so that I can set WARNS?=1 in libc before the code > freeze. You can safely assume that it won't change to floating before the code freeze :-). I think (t = n) would cause compiler warnings at higher WARNS levels if time_t were unsigned. `t == n' certainly would. `(long)(time_t)n == n' could be used (this is like the above except it doesn't use a temporary variable. However, the cast to long breaks the warning about the bug that if n is -1L and time_t is unsigned long, then the comarison will succeed on 2's complement machines although time_t cannot represent -1. Bruce