From owner-freebsd-hackers@FreeBSD.ORG Sun Jun 5 19:06:45 2011 Return-Path: Delivered-To: hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 26D97106566B; Sun, 5 Jun 2011 19:06:45 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay04.stack.nl [IPv6:2001:610:1108:5010::107]) by mx1.freebsd.org (Postfix) with ESMTP id BBA868FC15; Sun, 5 Jun 2011 19:06:44 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id 5A48A1DD648; Sun, 5 Jun 2011 21:06:43 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id 42717173D9; Sun, 5 Jun 2011 21:06:43 +0200 (CEST) Date: Sun, 5 Jun 2011 21:06:43 +0200 From: Jilles Tjoelker To: "Sean C. Farley" Message-ID: <20110605190643.GA62966@stack.nl> References: <4DEBC741.1020200@links.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: hackers@FreeBSD.org, Ben Laurie Subject: Re: int64_t and printf X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Jun 2011 19:06:45 -0000 On Sun, Jun 05, 2011 at 02:31:27PM -0400, Sean C. Farley wrote: > On Sun, 5 Jun 2011, Ben Laurie wrote: > > So, for example int64_t has no printf modifier I am aware of. Likewise > > its many friends. > > In the past I've handled this by having a define somewhere along the > > lines of... > > #if > > # define INT_64_T_FMT "%ld" > > #else > > # define INT_64_T_FMT "%lld" > > #endif > > but I have no idea where to put such a thing in FreeBSD. Opinions? > > Also, I guess I'd really need to do a modifier rather than a format, > > for full generality. > You need to include inttypes.h, which includes machine/_inttypes.h. > This will provide the appropriate macro which in this case is PRId64. The macros from are certainly valid, but the style in most of FreeBSD prefers casting to a type such as intmax_t or uintmax_t for which a constant format string is available (%jd/%ju). In the particular case of int64_t, it would seem that long long is better than intmax_t, as it is possibly shorter but still guaranteed large enough by C99, but there are objections against this that I do not understand. Also, note the format strings for size_t, %zu, and for ptrdiff_t, %td. -- Jilles Tjoelker