🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2303

Re: 'h' modifier in printf

#2303
From: Gordon Burditt
Date: Sat, 16 Mar 1996 16:21
29 lines
1112 bytes
>The "h" modifier says the corresponding argument will be printed as a
>short or unsigned short.
>
>So, given:
>
>short s;
>printf("%d", s);
>printf("%hd", s);

>Can these two ever be different?  

I don't think so, BUT:
short s = -1;
printf("%x\n", (unsigned int) s);
printf("%hx\n", (unsigned int) s);

/* is it allowed to leave out the casts? */

prints, on a machine with 16-bit shorts and 32-bit ints:

ffffffff
ffff

I believe this behavior in FreeBSD's gcc is correct, or at least allowed,
behavior for the given machine architecture.  The h modifier isn't
totally useless, just mostly so.

					Gordon L. Burditt
					sneaky.lerctr.org!gordon
Technical Details
Message-ID: <4iepq6$af6@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4i801c$455@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: gordon@sneaky.lerctr.org (Gordon Burditt)
Newsgroups: comp.lang.c.moderated,comp.std.c
Subject: Re: 'h' modifier in printf
Date: 16 Mar 1996 10:21:26 -0600
Organization: What organization?
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4iepq6$af6@solutions.solon.com>
References: <4i801c$455@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com