From owner-freebsd-arch Wed Oct 9 12:30:34 2002 Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6E62B37B401 for ; Wed, 9 Oct 2002 12:30:32 -0700 (PDT) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id EE81C43E4A for ; Wed, 9 Oct 2002 12:30:30 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id FAA19401; Thu, 10 Oct 2002 05:30:23 +1000 Date: Thu, 10 Oct 2002 05:40:30 +1000 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Andrew Gallatin Cc: Peter Wemm , Subject: Re: lp64 vs lp32 printf In-Reply-To: <15780.26700.615985.133379@grasshopper.cs.duke.edu> Message-ID: <20021010051056.C6361-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Wed, 9 Oct 2002, Andrew Gallatin wrote: > Peter Wemm writes: > > > > > > Um, using intmax_t to print size_t's would be incorrect, since it is > > > signed. Using uintmax_t would be bloat. Very few typedefed types > > > need the full bloat of [u]intmax_t, and size_t is unlikely to become > > > one of them before casting it to uintmax_t to print it becomes a style > > > bug in the kernel too (when %z is implemented). > > > > Bring it on! The sooner %z gets here the better. The only problem is that > > gcc has been taught that %z means something different in the kernel. :-( > > Where is gcc taught these things? Can we update it? From c-format.c: %%% /* BSD conversion specifiers. */ /* FreeBSD kernel extensions (src/sys/kern/subr_prf.c). The format %b is supported to decode error registers. Its usage is: printf("reg=%b\n", regval, "*"); which produces: reg=3 The format %D provides a hexdump given a pointer and separator string: ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX ("%*D", len, ptr, " ") -> XX XX XX XX ... */ { "D", 1, STD_EXT, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "cR" }, { "b", 1, STD_EXT, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "" }, { "rz", 0, STD_EXT, { T89_I, BADLEN, BADLEN, T89_L, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#", "i" }, { NULL, 0, 0, NOLENGTHS, NULL, NULL } %%% The "z" in "rz" here gives the FreeBSD extension. There seem to be no conflicts in practice, because %z is a format specifier (like %z) in the extension, but is (bogusly) a length modifer (like %l) in C99. Plain %z (which can only be reasonably interpreted as a format specifier) is implemented by the T89_I entry in the above table. This is broken, because -fformat-extensions (brokenly) doesn't turn off the things that are not supported by the kernel printf (e.g., %z as a length modifier), and gcc interprets %z as a length modifier first. But this is harmless because plain %z is not used in the kernel. %lz is used and still works because there is no ambiguity for %z. This is implemented by the T89_L intry in the above table. Format checking for printing size_t's using %zu (or %zd) works too, since there is no ambiguity. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message