ansi printf questions

Tony Parkhurst_TEMP tony at hp-sdd.hp.com
Tue Feb 7 04:18:20 AEST 1989


In article <15188 at oberon.USC.EDU> blarson at 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 at 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



More information about the Comp.std.c mailing list