From owner-freebsd-hackers@FreeBSD.ORG Sun Nov 2 03:58:33 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9A6E7A64; Sun, 2 Nov 2014 03:58:33 +0000 (UTC) Received: from mho-02-ewr.mailhop.org (mho-02-ewr.mailhop.org [204.13.248.72]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6A904F62; Sun, 2 Nov 2014 03:58:32 +0000 (UTC) Received: from [73.34.117.227] (helo=ilsoft.org) by mho-02-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1XkmJC-000HSJ-Vc; Sun, 02 Nov 2014 03:58:31 +0000 Received: from [172.22.42.240] (revolution.hippie.lan [172.22.42.240]) by ilsoft.org (8.14.9/8.14.9) with ESMTP id sA23wTap088564; Sat, 1 Nov 2014 21:58:29 -0600 (MDT) (envelope-from ian@FreeBSD.org) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 73.34.117.227 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX1/ves+QlHyRzfeKnB31PbMk X-Authentication-Warning: paranoia.hippie.lan: Host revolution.hippie.lan [172.22.42.240] claimed to be [172.22.42.240] Subject: Re: how to kernel printf a int64_t? From: Ian Lepore To: Julian Elischer In-Reply-To: <5455A2E3.40808@freebsd.org> References: <604180572.3888597.1414894484998.JavaMail.root@uoguelph.ca> <5455A2E3.40808@freebsd.org> Content-Type: text/plain; charset="iso-8859-13" Date: Sat, 01 Nov 2014 21:58:29 -0600 Message-ID: <1414900709.17308.243.camel@revolution.hippie.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by ilsoft.org id sA23wTap088564 Cc: Freebsd hackers list , Rick Macklem X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Nov 2014 03:58:33 -0000 On Sun, 2014-11-02 at 11:20 +0800, Julian Elischer wrote: > On 11/2/14, 10:14 AM, Rick Macklem wrote: > > Julian Elischer wrote: > >> On 10/31/14, 1:09 PM, Tim Kientzle wrote: > >> > >> > >> On Oct 30, 2014, at 2:01 PM, Rick Macklem > >> wrote: > >> > >> Hi, > >> > >> I feel kinda dumb asking this, but... > >> int64_t i; > >> > >> printf("%qd\n", (u_quad_t)i); > >> > >> works but looks dorky, to put it technically;-). > >> Is there a better way to printf() a int64_t in the kernel? I often > >> use the following to print large integers: > >> > >> printf(=B4%jd\n=A1, (intmax_t)i); the "cannonical' way is to us= e > >> PRIu64 and friends, but some people seem to have a problem with > >> doing that. > >> > > Ok, so now I need to ask another dumb question. > > How do you do this in the kernel? > > (I can see them defines in , but including that > > doesn't help, which isn't surprising since PRIu64 is in a string > > and won't be recognized as a macro.) >=20 > you use it with string concatenation. > like: >=20 > printf (" this is a 64 it unsigned value: %" PRIu64 " and I just=20 > printed it\n", thingy64); >=20 > After substitution the compiler sees > " this is a 64 it unsigned value: %" "llu" " and I just printed it\n" > which simplifies to: > " this is a 64 it unsigned value: %llu and I just printed it\n" >=20 > due to concatenation. (note I didn't actually look what PRIu64=20 > evaluates to) >=20 >=20 Which is exactly the explanation for why "some people seem to have a problem with doing that." "Some people" would be "anyone who thinks it should be possible to read code as well as write it." This may be more correct in some pedantic sense, but %j and a cast is more readable. -- Ian > > > > Oh, and is intmax_t going to be int64_t on all arches? > > > > Thanks, rick > > > >> > >> Tim > >> > >> _______________________________________________ > >> freebsd-hackers@freebsd.org mailing list > >> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To > >> unsubscribe, send any mail to > >> "freebsd-hackers-unsubscribe@freebsd.org" > >> > > > > >=20 > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.o= rg" >=20