From owner-freebsd-arch Sun Jun 3 1:53:36 2001 Delivered-To: freebsd-arch@freebsd.org Received: from mailg.telia.com (mailg.telia.com [194.22.194.26]) by hub.freebsd.org (Postfix) with ESMTP id 5EEE237B403 for ; Sun, 3 Jun 2001 01:53:30 -0700 (PDT) (envelope-from ertr1013@student.uu.se) Received: from d1o913.telia.com (d1o913.telia.com [195.252.44.241]) by mailg.telia.com (8.11.2/8.11.0) with ESMTP id f538rTq07830 for ; Sun, 3 Jun 2001 10:53:29 +0200 (CEST) Received: from ertr1013.student.uu.se (h185n2fls20o913.telia.com [212.181.163.185]) by d1o913.telia.com (8.8.8/8.8.8) with SMTP id KAA25114 for ; Sun, 3 Jun 2001 10:53:28 +0200 (CEST) Received: (qmail 34820 invoked by uid 1001); 3 Jun 2001 08:53:11 -0000 Date: Sun, 3 Jun 2001 10:53:11 +0200 From: Erik Trulsson To: arch@FreeBSD.ORG Subject: Re: time_t definition is wrong Message-ID: <20010603105311.A34715@student.uu.se> Mail-Followup-To: arch@FreeBSD.ORG References: <200106012318.f51NI8w38590@bunrab.catwhisker.org> <20010602085237.A73968@dragon.nuxi.com> <200106021739.f52Hd9V03943@earth.backplane.com> <200106022043.f52KhFh35078@vashon.polstra.com> <20010603011621.A88949@dragon.nuxi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010603011621.A88949@dragon.nuxi.com>; from obrien@FreeBSD.ORG on Sun, Jun 03, 2001 at 01:16:21AM -0700 Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sun, Jun 03, 2001 at 01:16:21AM -0700, David O'Brien wrote: > On Sat, Jun 02, 2001 at 01:43:15PM -0700, John Polstra wrote: > > I'd prefer to keep it as "long" at least on the i386, because that's > > what the type was for years before ANSI renamed it to "time_t". > > We will have to special case all of our code that uses time_t and > printf() since our 64-bit types will be "%d", not "%ld", and we'll have > to hope all the i386 users remember that when they change things in > /usr/src/. I still think it is better to use a consistent time_t > definition (and printf format specifier) across all FreeBSD platforms. > > But if the wind is really swaying that way... I'll concede. Code that uses time_t should be written to work regardless of if time_t is defined as 'long', 'int' or 'short' (the last last one is a bit unlikely though :-) ) So if one has time_t t; then both printf("%d",t) and printf("%ld",t) are wrong and should be fixed. Programmers making unwarranted assumptions about the size of time_t and the corresponding printf format specifier should get a clue or two and stop doing that. The correct thing to do is printf("%ld",(long)t) which will work just fine with both ints and longs. If one has C99-aware headers/libraries then the correct thing to do is printf("%jd",(intmax_t)t) which will work for all signed integer types. Although the C standard allows time_t to be any arithmetic type I think one can safely assume that it will be a (signed) integer type on Unix systems (including FreeBSD). On i386 everything should work fine regardless of whether time_t is defined as 'int' or 'long' as long as they are both 32-bit. The worst that can happen is some (well-deserved) compiler warnings. Eventually time_t will have to be changed to a 64-bit type but then it will probably be spelled 'long long' (or, preferably, int64_t assuming FreeBSD has C99-compatible header files by then.) (Changing the size of time_t, especially if time_t no longer could fit n a 'long', will almost certainly break lots of programs and require quite a bit of work to fix.) -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message