vfprintf() string precision type

Sean C. Farley scf at FreeBSD.org
Mon Sep 17 16:35:39 PDT 2007

On Mon, 17 Sep 2007, Harti Brandt wrote:

> On Sun, 16 Sep 2007, Sean C. Farley wrote:
> SCF>Xin LI noticed a warning in the code I wrote for setenv() where a
> SCF>precision was provided with a string argument to warnx() (really
> SCF>vfprintf()).  The warning appearing on amd64 and not i386 showed
> SCF>that precisions are always 32-bit.
> SCF>
> SCF>Would it be better to change the precision handling to expect
> SCF>size_t?  My reasoning is that strlen() and sizeof both return
> SCF>size_t.  It makes a cast unnecessary for passing a value returned
> SCF>by either call as the precision.  Unfortunately, I could find
> SCF>nothing from SUSv3 that specified what type the precision could
> SCF>be.
> The argument to the %.*f is specified to be an int ( so I
> would assume that internal handling in printf() also uses int.
> Paragraph 4 of the above section talks about the precision as 'an
> optional decimal integer'. Well, one could interpret this to mean int,
> but need not to.

Yes, I see your point.  It should be int, but it would be nice for the
spec to say size_t.  :)

> PS: Not sure that I got your question right :-)

You did.  Thank you.

scf at FreeBSD.org

More information about the freebsd-standards mailing list