Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!think.com!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.std.c Subject: Re: ANSI printf Message-ID: Date: 7 Mar 91 22:47:32 GMT References: <1830@manta.NOSC.MIL> Sender: news@OSF.ORG Organization: Open Software Foundation Lines: 30 In-reply-to: mitch@manta.NOSC.MIL's message of 7 Mar 91 18:01:37 GMT In article <1830@manta.NOSC.MIL> mitch@manta.NOSC.MIL (Ray Mitchell) writes: | | 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.) Consider on a machine that has 16 bit shorts and 32 bit longs: short i = 0x8000; printf ("%#hx", i); you want 0x8000 printed, and not 0xffff8000. -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142 Considering the flames and intolerance, shouldn't USENET be spelled ABUSENET?