Date: Sun, 5 Jun 2011 21:06:43 +0200 From: Jilles Tjoelker <jilles@stack.nl> To: "Sean C. Farley" <scf@FreeBSD.org> Cc: hackers@FreeBSD.org, Ben Laurie <ben@links.org> Subject: Re: int64_t and printf Message-ID: <20110605190643.GA62966@stack.nl> In-Reply-To: <alpine.BSF.2.02.1106051426190.9196@thor.farley.org> References: <4DEBC741.1020200@links.org> <alpine.BSF.2.02.1106051426190.9196@thor.farley.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <something> > > # 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 <inttypes.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110605190643.GA62966>