[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Please test pending bugfix release of base

From: David Chisnall
Subject: Re: Please test pending bugfix release of base
Date: Sat, 18 Jun 2011 14:30:37 +0100

On 18 Jun 2011, at 14:07, Richard Frith-Macdonald wrote:

> The solution here might be to cast the argument to match the format string 
> rather than trying to make the format string fit the argument.  The only 
> problem with that is a possible loss of precision when casing a 64bit value 
> to int/unsigned.  I'm not really certain what the *ideal* solution is.

C comes with a convenient set of macros to solve this kind of problem, in 
inttypes.h.  The macro PRIdPTR will expand to either d or lld, depending on 
whether intptr_t is int or long long (or to something else, if applicable).  
Since NS[U]Integer is the same as [u]intptr_t, then it seems to make sense to 
use these macros.  Format strings can be written as:

NSLog(@"some integer: %" PRIdPTR, someNSInteger);

Note: This does not work with strings being localised.  In that case, casting 
to long and using %ld or %lu is probably better (this is what Apple recommends).


-- Sent from my PDP-11

reply via email to

[Prev in Thread] Current Thread [Next in Thread]