how to kernel printf a int64_t?

Tim Kientzle tim at kientzle.com
Sun Nov 2 17:23:51 UTC 2014


> On Nov 1, 2014, at 6:46 PM, Paul Koch <paul.koch at akips.com> wrote:
> 
> On Sun, 02 Nov 2014 09:23:04 +0800
> Julian Elischer <julian at freebsd.org> wrote:
> 
>> On 10/31/14, 1:09 PM, Tim Kientzle wrote:
>>> On Oct 30, 2014, at 2:01 PM, Rick Macklem <rmacklem at uoguelph.ca> wrote:
>>> 
>>>>       int64_t i;
>>>> 
>>>>       printf("%qd\n", (u_quad_t)i);
>>>> 
>>>> Is there a better way to printf() a int64_t in the kernel?
>>> 
>>>     printf(“%jd\n”, (intmax_t)i);
> 
> We've always used the PRIxxx types when coding for both 32/64 platforms,
> but it would have been really nice to have a standard way for time_t.
> Something like PRItt

This is the major reason I prefer the intmax_t cast approach: the PRI* macros only support a small handful of basic integer types.

The intmax_t cast approach only requires you to know whether it's signed (%jd with intmax_t) or unsigned (%ju with uintmax_t).


> On Nov 1, 2014, at 7:14 PM, Rick Macklem <rmacklem at uoguelph.ca> wrote:

> Oh, and is intmax_t going to be int64_t on all arches?

Yes, until we start supporting 128-bit arithmetic.  So the only runtime cost for this approach is that it might have to widen the value.  (Given the cost of printf in general, that's likely not a problem.)

Tim



More information about the freebsd-hackers mailing list