Date: Sun, 3 Jun 2001 10:53:11 +0200 From: Erik Trulsson <ertr1013@student.uu.se> To: arch@FreeBSD.ORG Subject: Re: time_t definition is wrong Message-ID: <20010603105311.A34715@student.uu.se> In-Reply-To: <20010603011621.A88949@dragon.nuxi.com>; from obrien@FreeBSD.ORG on Sun, Jun 03, 2001 at 01:16:21AM -0700 References: <200106012318.f51NI8w38590@bunrab.catwhisker.org> <20010602085237.A73968@dragon.nuxi.com> <200106021739.f52Hd9V03943@earth.backplane.com> <p05100e0fb73ee9d458f7@[128.113.24.47]> <200106022043.f52KhFh35078@vashon.polstra.com> <20010603011621.A88949@dragon.nuxi.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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.) -- <Insert your favourite quote here.> Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010603105311.A34715>