Re: short question but I don't know how to describe it
Re: short question but I don't know how to describe it
- Subject: Re: short question but I don't know how to describe it
- From: Greg Parker <email@hidden>
- Date: Mon, 8 Mar 2010 16:04:18 -0800
On Mar 8, 2010, at 3:54 PM, Clark Cox wrote:
> For types smaller than int, there is no need to explicitly cast; the
> standard guarantees that such values are converted to int (or unsigned
> int) implicitly. In fact, the 'h' and 'hh' modifiers are completely
> redundant and are ignored when passed to printf-like functions
... unless you're printing signed variables using %x, for one.
% cat test.c
#include <stdio.h>
int main() {
short x = -1;
printf("hx 0x%hx\n", x);
printf("x 0x%x\n", x);
return 0;
}
% cc test.c
% ./a.out
hx 0xffff
x 0xffffffff
(Hint: Implicit promotion to int, and sign extension.)
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden