Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Aug 2010 09:27:30 -0700
From:      Bakul Shah <bakul@bitblocks.com>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        mdf@FreeBSD.org, freebsd-arch@FreeBSD.org
Subject:   Re: RFC: replace vm_offset_t with uintptr_t and vm_size_t with size_t 
Message-ID:  <20100815162730.BC15B5B04@mail.bitblocks.com>
In-Reply-To: Your message of "Fri, 13 Aug 2010 19:46:42 %2B1000." <20100813191149.V12776@delplex.bde.org> 
References:  <AANLkTik_2pXA1LP9dq-iOLkFrQBG7jP=4yUXBjtDOBF3@mail.gmail.com> <20100813191149.V12776@delplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 13 Aug 2010 19:46:42 +1000 Bruce Evans <brde@optusnet.com.au>  wrote:
> 
> I prefer to fix printf.  There should be a %I format something like in
> sfio.  Unfortunately C99 only standardized the PRI* mistake.  I never
> learned exactly what %I does, but think it should have 2 variations,
> something like a plain %I causing the compiler to rewrite the literal
> format string, replacing %I with the appropriate Standard format, and
> %I<width> for interpretation by the library.  -Wformat has done all the
> work needed to determine the correct replacement for 10-20 years.  So
> vm_offset's and size_t's would normally be printed using "%I[xu]" (no
> need for %z), but in message catalogues they would be printed using
> 
>      ("...%I*[xu] %I*[xu]...", ...
>      sizeof(vm_offset_t) * CHAR_BIT, var_of_type_vm_offset_t,
>      sizeof(size_t) * CHAR_BIT,  var_of_type_vm_offset_t, ...)
> 
> Except that came out too painful (almost as bad as using PRI*).  I
> think I would usually avoid using %I<width> if it were as messy as
> this, and use %j and require all integer args to be of type [u]intmax_t.
> 
> %I could also be a more global directive (either at the front of every
> literal format string that wants rewriting for all args, or in CFLAGS
> for all strings in a file).

Have you looked at plan9's fmtinstall(3)? Basically
fmtinstall('x', foo) will install function foo to be called
when %...x is seen in a format string. foo takes struct Fmt*
which points to stuff needed for formatting. Things like
width, precision, flags, whether output buffer is runes or
chars etc.  Once you install the formats you need, their use
becomes pretty painless.  Perhaps kernel's printf can be
extended (or rebuilt) using this idea?  Seems to me something
like that would be better and much more extensible than
inflicting %I*[xu].  This does not require compiler magic but
you also lose the -Wformat crutch.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100815162730.BC15B5B04>