ANSI printf

Ray Mitchell mitch at manta.NOSC.MIL
Fri Mar 8 04:01:37 AEST 1991


This question concerns the use of the "h" modifier in a printf conversion
specification.  According to ANSI C, %hi, %hd, etc. indicate that the
corresponding argument is to be printed as a short integer.  However, since
all but the first printf argument are prototyped as being variable arguments,
the usual default argument type conversions must occur.  Therefore, any
argument of type short will be converted to int before being passed.  If ints
and shorts are the same size, no problem.  If ints are larger than shorts,
i.e., 32 bit ints and 16 bit shorts, still no problem since printf can
use either all 32 bits or only the original 16 and the value will be the
same.  As far as print format is concerned, doesn't a short get printed in the
same format as an int?  If this is the case, I fail to see any reason for the
existance of "h" since some bizzare form of "lint" would be the only thing
that could detect a type mismatch.  (I know there must be something I
am missing on this.)


				Ray Mitchell



More information about the Comp.std.c mailing list