🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2528

ANSI printf

#2528
From: Ray Mitchell
Date: Thu, 07 Mar 1991 18:01
18 lines
1391 bytes
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
Technical Details
Message-ID: <1830@manta.NOSC.MIL>
Path: arc1-ca.pugleaf.net!utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!ncis.tis.llnl.gov!dog.ee.lbl.gov!nosc!manta!mitch

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!ncis.tis.llnl.gov!dog.ee.lbl.gov!nosc!manta!mitch
From: mitch@manta.NOSC.MIL (Ray Mitchell)
Newsgroups: comp.std.c
Subject: ANSI printf
Keywords: printf
Message-ID: <1830@manta.NOSC.MIL>
Date: 7 Mar 91 18:01:37 GMT
Organization: Naval Ocean Systems Center, San Diego
Lines: 18