[quagga-dev 4398] Re: bgpd printf size_t warning
Andrew J. Schorr
aschorr at telemetry-investments.com
Sun Sep 24 23:09:50 BST 2006
On Sun, Sep 24, 2006 at 02:25:12PM -0400, Greg Troxel wrote:
> I'm for adding the casts, so we get arguably-correct code, and adding
> a /* XXX size_t */ before the printf.
> But I don't have a strong opinion.
That sounds like a good compromise to me. I'm going to do that,
unless somebody objects.
So that solves the problem of how to print a size_t. Now suppose
it's a u_int32_t (like OSPF_IF_PARAM(oi, v_wait)). First, note
that the C99 standard type would be uint32_t, although this is optional.
(Refer to section 7.18 of the C-99 spec, or take a look in <stdint.h>
To be really C99-compliant, I guess you have to use uint_least32_t,
or uint_fast32_t (since uint32_t is optional). And then one should
say something like
printf("value is %"PRIuFAST32"\n",OSPF_IF_PARAM(oi, v_wait));
But do we really want to get started with this insanity, or just
cast to u_long? If we do decide to use these C99 features, then
we may as well take David's suggestion and have our own macro
_PRISIZET and make it conditional on the platform (so %zu on most).
More information about the Quagga-dev