NSInteger and NSUInteger


dhoerl
 

Xcode list 2013:

Date: Sun, 17 Nov 2013 15:38:22 -0500
From: Andy Lee <aglee@...>
To: "Gerriet M. Denkmann" <gerriet@...>
Cc: Xcode Users <xcode-users@...>
Subject: Re: printing NSUInteger in iOS
Message-ID: <E2CA2BAA-E03C-4850-8F42-7D3611A21C75@...>
Content-Type: text/plain; charset=us-ascii

I've been grudgingly casting, but there is this, which I haven't yet memorized:

<https://twitter.com/gparker/status/377910611453046784>
%zd, %tu, %tx (signed, unsigned, hex) currently format NSInteger and NSUInteger with no warnings.
--Andy


dhoerl
 

Original post of this solution came from no other than Greg Parker!


Steve Christensen <punster@...>
 

On Jul 10, 2017, at 6:13 AM, Steve Mills <sjmills@...> wrote:

On Jul 10, 2017, at 04:54:24, Gerriet M. Denkmann <g@...> wrote:

Formats for NS(U)Integer:
%t… (%td, %to, %tu %tx, %tX) for unsigned results NSUInteger
%z… (%zd, %zo, %zu %zx, %zX) for signed results NSInteger

Where did you find this info? I've seen mention of them, but never an official type doc that lists them.

General information on format specifiers is here:


I use %td for NSInteger and %tu for NSUInteger. The 't' is a length modifier specifying that a following d, o, u, x, or X conversion specifier applies to a ptrdiff_t or the corresponding unsigned integer type argument. That allows you to use the same format specifier for both 32- and 64-bit platforms, get the correct results, and avoid compiler warnings.


Gerriet M. Denkmann
 

On 10 Jul 2017, at 20:36, Dave <dave@...> wrote:

Thanks a lot for this - where did you find it?
Probably this was posted on Apple’s CocoaDev mailing list by someone who surely knows about these things.

Gerriet.


Dave
 

Hi,

Thanks a lot for this - where did you find it?

Cheers
Dave

On 10 Jul 2017, at 11:54, Gerriet M. Denkmann <g@...> wrote:


On 10 Jul 2017, at 16:37, Dave <dave@...> wrote:

I’m trying to use NSInteger and/or NSUInteger in a InitWithFormat statement, I’m using %ld as the specifier but this is producing warnings? Has this changed recently, because code that used to compile without warnings now cause warnings. What is the correct specifier to use for these types?
Formats for NS(U)Integer:
%t… (%td, %to, %tu %tx, %tX) for unsigned results NSUInteger
%z… (%zd, %zo, %zu %zx, %zX) for signed results NSInteger

Gerriet.




Steve Mills
 

On Jul 10, 2017, at 04:54:24, Gerriet M. Denkmann <g@...> wrote:


Formats for NS(U)Integer:
%t… (%td, %to, %tu %tx, %tX) for unsigned results NSUInteger
%z… (%zd, %zo, %zu %zx, %zX) for signed results NSInteger
Where did you find this info? I've seen mention of them, but never an official type doc that lists them.

--
Steve Mills
Drummer, Mac geek


Gerriet M. Denkmann
 

On 10 Jul 2017, at 16:37, Dave <dave@...> wrote:

I’m trying to use NSInteger and/or NSUInteger in a InitWithFormat statement, I’m using %ld as the specifier but this is producing warnings? Has this changed recently, because code that used to compile without warnings now cause warnings. What is the correct specifier to use for these types?
Formats for NS(U)Integer:
%t… (%td, %to, %tu %tx, %tX) for unsigned results NSUInteger
%z… (%zd, %zo, %zu %zx, %zX) for signed results NSInteger

Gerriet.


Dave
 

Hi,

I’m trying to use NSInteger and/or NSUInteger in a InitWithFormat statement, I’m using %ld as the specifier but this is producing warnings? Has this changed recently, because code that used to compile without warnings now cause warnings. What is the correct specifier to use for these types?

Thanks a lot
All the Best
Dave