[MLton] %zu printf formatter does not port

Matthew Fluet fluet at tti-c.org
Wed Aug 15 11:09:08 PDT 2007


On Wed, 15 Aug 2007, Ville Laurikari wrote:
> On HP-UX, printf does not implement the "z" length specifier (for
> printing size_t values).  GCC is not aware that %z does not work, and
> gives no warning.

Blech.  That seems kind of broken, but oh well.

> I suppose it's OK to change the occurrences of %zu to a macro.  This
> would be defined by the appropriate platform/<os>.h to something which
> works on the current platform.
>
> How does PRIusz (accompanied with FMTusz) sound?  It appears that for
> size_t there are no predefined macros in the spirit of PRIu32 and
> friends.  We would then also need a typedef to cast printf arguments
> to match the printf formatter.  This could be called "priusz".

I'd say that PRIuSZ is more in keeping with the other macros.
Though I kind of dislike needing to add a #define PRIuSZ in every 
platform.

> Alternatively, we could cast size_t to uintmax_t and use PRIuMAX for
> printing.  The advantage with this would be that the printf macros are
> already defined so there would be less changes overall.

I'm slightly in preference for this alternative.  Though, I know that on 
some platforms, I get a bunch of warnings that
   warning: ISO C does not support the `q' printf length modifier
when PRIuMAX yields (the non-C99 modifier) "q", which will only increase 
with more printfs using PRIuMAX.





More information about the MLton mailing list