• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: -Wformat only warns about NSInteger as printf param in 32-bit builds
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -Wformat only warns about NSInteger as printf param in 32-bit builds


  • Subject: Re: -Wformat only warns about NSInteger as printf param in 32-bit builds
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 02 Feb 2016 15:18:14 -0800
  • Feedback-id: 167118m:167118agrif8a:167118sZ78LDQOuc:SMTPCORP

On Feb 2, 2016, at 11:45 , Jens Alfke <email@hidden> wrote:

(To be clear: I understand why this behaves differently, due to the [awful] decision to make NSInteger different sizes in 32-bit vs 64-bit. But at a high level it’s an inconsistent warning, when you have multiple platforms to build for.)

As suggested by Greg Parker on this list a couple of years ago, you can use

%t… (%td, %to, %tu %tx, %tX) for unsigned results
%z… (%zd, %zo, %zu %zx, %zX) for signed results

and these work on NS[U]Integer-sized variables on all platforms and architectures that are supported by Apple (without having to cast the parameters).

The ’t’ or ‘z’ controls whether the conversion is unsigned or signed. The ‘d’ or ‘u’ controls whether the parameter is an signed or unsigned variable. This is kinda a distinction without a difference, so, normally, it’s %tu for NSUInteger, and %zd for NSInteger.

These modifiers are documented here:

https://developer.apple.com/library/prerelease/watchos/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

but using them for this purpose is a trick that is (AFAIK) Greg’s own brain-storm.

 _______________________________________________
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

References: 
 >-Wformat only warns about NSInteger as printf param in 32-bit builds (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: -Wformat only warns about NSInteger as printf param in 32-bit builds
  • Next by Date: Problem with Debugger Showing Object as a Collection?
  • Previous by thread: Re: -Wformat only warns about NSInteger as printf param in 32-bit builds
  • Next by thread: Problem with Debugger Showing Object as a Collection?
  • Index(es):
    • Date
    • Thread