From owner-freebsd-questions@FreeBSD.ORG Thu Jan 17 14:24:35 2013 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 36F6E2FF for ; Thu, 17 Jan 2013 14:24:35 +0000 (UTC) (envelope-from freebsd-questions-local@be-well.ilk.org) Received: from asbnvacz-mailrelay01.megapath.net (asbnvacz-mailrelay01.megapath.net [207.145.128.243]) by mx1.freebsd.org (Postfix) with ESMTP id F32651CC for ; Thu, 17 Jan 2013 14:24:34 +0000 (UTC) Received: from mail5.sea5.speakeasy.net (mail5.sea5.speakeasy.net [69.17.117.49]) by asbnvacz-mailrelay01.megapath.net (Postfix) with ESMTP id 4BAB0A72C89 for ; Thu, 17 Jan 2013 09:24:34 -0500 (EST) Received: (qmail 20537 invoked from network); 17 Jan 2013 14:24:33 -0000 Received: by simscan 1.4.0 ppid: 25430, pid: 10518, t: 0.1824s scanners: clamav: 0.88.2/m:52/d:10739 Received: from unknown (HELO be-well.ilk.org) ([66.92.78.145]) (envelope-sender ) by mail5.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 17 Jan 2013 14:24:33 -0000 Received: from lowell-desk.lan (lowell-desk.lan [172.30.250.8]) by be-well.ilk.org (Postfix) with ESMTP id F14ED33C1D; Thu, 17 Jan 2013 09:24:27 -0500 (EST) Received: by lowell-desk.lan (Postfix, from userid 1147) id DC47839855; Thu, 17 Jan 2013 09:24:27 -0500 (EST) From: Lowell Gilbert To: Polytropon Subject: Re: time_t definition References: <50F5A189.7000701@speakeasy.org> <20130116120015.3b8d0db4@mr129166> <50F6EDFB.70501@speakeasy.org> <20130117011721.69799ef6.freebsd@edvax.de> Date: Thu, 17 Jan 2013 09:24:27 -0500 In-Reply-To: <20130117011721.69799ef6.freebsd@edvax.de> (Polytropon's message of "Thu, 17 Jan 2013 01:17:21 +0100") Message-ID: <44622vx4ys.fsf@lowell-desk.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain Cc: "Thomas D. Dean" , "questions@FreeBSD.org" , Michael Sierchio X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jan 2013 14:24:35 -0000 Polytropon 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.