Article View: comp.std.c
Article #5700Re: ansi printf questions
From: Tony Parkhurst_TEMP
Date: Mon, 06 Feb 1989 18:18
Date: Mon, 06 Feb 1989 18:18
31 lines
1719 bytes
1719 bytes
In article <15188@oberon.USC.EDU> blarson@skat.usc.edu (Bob Larson) writes:
>Thanks to all who answered %i is the same as %d in *printf. (They
>do differ in *scanf.)
>One further question: On a machine with 16 bit short and 32 bit int,
>what should:
>printf("%hd", 65537);
>print? 65537 (ignore the h)? 1 (truncate to short)? unspecified?
This is answered in the same way as your other question. Only makes a
difference in scanf. Remember that shorts are promoted to ints when
passed on the stack. So, since your constant is not qualified, the
65537 is passed to printf as an int. Since you can't pass a short on
a stack, 'h' is ignored. In scanf, you pass a pointer to a short, so the
'h' is necessary.
If you are planning on posting your vprintf, then you might consider one more
difficulty, that is, ints being 16 bits and longs being 32. Creates no
end of problems, but these are still used. In this case, 'l' is very important
in both printf and scanf.
-- Tony
--
Tony Parkhurst ( tony@hp-sdd.HP.COM )
"Is this Hell? Or is this Texas?" "Both" -- Heinlein, _J_O_B: _A _C_o_m_e_d_y _o_f _J_u_s_t_i_c_e
Technical Details
Message-ID:
<1738@hp-sdd.hp.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-sdd!tonyReferences:
<15159@oberon.USC.EDU> <9591@smoke.BRL.MIL> <372@twwells.uucp> <9594@smoke.BRL.MIL> <15188@oberon.USC.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-sdd!tony From: tony@hp-sdd.hp.com (Tony Parkhurst_TEMP) Newsgroups: comp.std.c Subject: Re: ansi printf questions Message-ID: <1738@hp-sdd.hp.com> Date: 6 Feb 89 18:18:20 GMT References: <15159@oberon.USC.EDU> <9591@smoke.BRL.MIL> <372@twwells.uucp> <9594@smoke.BRL.MIL> <15188@oberon.USC.EDU> Sender: news@hp-sdd.hp.com Reply-To: tony@hp-sdd.hp.com.UUCP (Tony Parkhurst_TEMP) Organization: Hewlett-Packard, San Diego Division Lines: 31