Date: Thu, 17 Jan 2013 09:24:27 -0500 From: Lowell Gilbert <freebsd-questions-local@be-well.ilk.org> To: Polytropon <freebsd@edvax.de> Cc: "Thomas D. Dean" <tomdean@speakeasy.org>, "questions@FreeBSD.org" <questions@freebsd.org>, Michael Sierchio <kudzu@tenebras.com> Subject: Re: time_t definition Message-ID: <44622vx4ys.fsf@lowell-desk.lan> In-Reply-To: <20130117011721.69799ef6.freebsd@edvax.de> (Polytropon's message of "Thu, 17 Jan 2013 01:17:21 %2B0100") References: <50F5A189.7000701@speakeasy.org> <20130116120015.3b8d0db4@mr129166> <50F6EDFB.70501@speakeasy.org> <CAHu1Y71L0fuQPgN044-GDr8NBPAo=n%2B6HSBv7Zi%2ByXTceYTZCA@mail.gmail.com> <20130117011721.69799ef6.freebsd@edvax.de>
index | next in thread | previous in thread | raw e-mail
Polytropon <freebsd@edvax.de> writes: > On Wed, 16 Jan 2013 10:21:03 -0800, Michael Sierchio wrote: >> Top posting for brevity - the fact is, the code in your original >> example is wrong. There are reasons to complain about argument size >> mismatches, esp. in print functions that call (versions of) malloc. >> You should cast the time_t value explicitly, or use %d instead of %ld. > > This advice looks correct. If you use the source Luke, > you'll find the following (taken from a 8.2-STABLE/i386 > system source tree): > > /usr/src/sys/sys/types.h (line 253): > > typedef __time_t time_t; > > /usr/src/sys/i386/include/_types.h (line 97): > > typedef __int32_t __time_t; > > /usr/src/sys/i386/include/_types.h (line 55): > > typedef int __int32_t; > > So it boils down to (int), but %ld expects (long). This > is the exact content of the warning. You can either > case the (time_t) value to (long), or change %ld to %d > to avoid the warning. Even if the representations boil down to the same thing, the cast is still a good idea. You may *know* (for example) that time_t is really an int, but you don't know that it always will be. printf() (like other variadic functions) loses type information, so make *sure* you cast the type to what the format says it is, because the Usual Arithmetic Conversions cannot come in to save your bacon if (when) you're wrong.home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44622vx4ys.fsf>
