From owner-freebsd-hackers@FreeBSD.ORG Sun Nov 2 03:20:15 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 CAF085AB for ; Sun, 2 Nov 2014 03:20:15 +0000 (UTC) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "vps1.elischer.org", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 9F2D3C79 for ; Sun, 2 Nov 2014 03:20:15 +0000 (UTC) Received: from jre-mbp.elischer.org (ppp121-45-239-104.lns20.per1.internode.on.net [121.45.239.104]) (authenticated bits=0) by vps1.elischer.org (8.14.9/8.14.9) with ESMTP id sA23KAos017098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Sat, 1 Nov 2014 20:20:13 -0700 (PDT) (envelope-from julian@freebsd.org) Message-ID: <5455A2E3.40808@freebsd.org> Date: Sun, 02 Nov 2014 11:20:03 +0800 From: Julian Elischer User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Rick Macklem Subject: Re: how to kernel printf a int64_t? References: <604180572.3888597.1414894484998.JavaMail.root@uoguelph.ca> In-Reply-To: <604180572.3888597.1414894484998.JavaMail.root@uoguelph.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Cc: Freebsd hackers list 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:20:15 -0000 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(ā€œ%jd\nā€, (intmax_t)i); the "cannonical' way is to use >> 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.) you use it with string concatenation. like: printf (" this is a 64 it unsigned value: %" PRIu64 " and I just printed it\n", thingy64); 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" due to concatenation. (note I didn't actually look what PRIu64 evaluates to) > > 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" >> > >