[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).
David
-- Sent from my PDP-11
- Please test pending bugfix release of base, Richard Frith-Macdonald, 2011/06/16
- Re: Please test pending bugfix release of base, Quentin Mathé, 2011/06/18
- Cleanup of memory on process exit, Richard Frith-Macdonald, 2011/06/19
- Re: Cleanup of memory on process exit, Quentin Mathé, 2011/06/19
- Re: Please test pending bugfix release of base, Ivan Vučica, 2011/06/18
- Re: Please test pending bugfix release of base, Sebastian Reitenbach, 2011/06/18
- Re: Please test pending bugfix release of base, Richard Frith-Macdonald, 2011/06/18
- Re: Please test pending bugfix release of base, David Chisnall, 2011/06/18
- Re: Please test pending bugfix release of base, Richard Frith-Macdonald, 2011/06/18
Re: Please test pending bugfix release of base, Quentin Mathé, 2011/06/18