Thursday, September 12, 2013

Formatting NSInteger and NSUInteger

Greg Parker:

%zd, %tu, %tx (signed, unsigned, hex) currently format NSInteger and NSUInteger with no warnings.

The printf(3) man page:

Note: the t modifier, when applied to a o, u, x, or X conversion, indicates that the argument is of an unsigned type equivalent in size to a ptrdiff_t. The z modifier, when applied to a d or i conversion, indicates that the argument is of a signed type equivalent in size to a size_t.

Apple’s String Format Specifiers documentation still recommends casting to long or unsigned long and using %ld or %lu.

Comments RSS · Twitter

Leave a Comment