Re: 4.5 and NSInteger/NSUInteger Format Specifier Warnings
Re: 4.5 and NSInteger/NSUInteger Format Specifier Warnings
- Subject: Re: 4.5 and NSInteger/NSUInteger Format Specifier Warnings
- From: Eric Wing <email@hidden>
- Date: Wed, 03 Oct 2012 12:51:20 -0700
On 10/3/12, Tom Seddon <email@hidden> wrote:
> `%u' or `%lu' would be more appropriate for an unsigned value.
>
> This sort of warning IS difficult to fix reliably for mixed 32-/64-bit code,
> though. I don't know if there's an approved solution, but I never found any
> obvious fix other than the cast. So I've just stopped using the NS types
> wherever possible...
Here's an idea I just had. Maybe we should take inspiration from C99's
inttypes.h and the PRI* macros.
So we do something like:
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) ||
TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
#define PRI_NSINT "ld"
#define PRI_NSUINT "lu"
#else
#define PRI_NSINT "d"
#define PRI_NSUINT "u"
#endif
Then to use it, do something like:
NSInteger my_int = NSIntegerMax;
NSUInteger my_uint = NSUIntegerMax;
printf("NSIntegerMax is %" PRI_NSINT " and NSUIntegerMax is %"
PRI_NSUINT "\n", my_int, my_uint);
NSLog(@"NSIntegerMax is %" PRI_NSINT " and NSUIntegerMax is %"
PRI_NSUINT, my_int, my_uint);
This should work cleanly for 32-bit and 64-bit and at least has some
consistency with C99 conventions.
Maybe we can rally around some good macro names (I'm not married to
PRI_NSINT) and a good header file name and put the header on
GitHub/Bitbucket for the community to adopt. We should also fill in
other missing ones like CGFloat.
Thanks,
Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden