• 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
-Wformat only warns about NSInteger as printf param in 32-bit builds
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: -Wformat only warns about NSInteger as printf param in 32-bit builds
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 02 Feb 2016 11:45:43 -0800

The -Wformat compiler warning option (“Typecheck calls to printf/scanf”) complains about the use of NSIntegers as parameters to printf-style functions … but only on iOS. (Or maybe only on 32-bit builds?) This is a PITA when developing cross-platform code — I do most of my development targeting Mac OS because it’s easier to run, but then I’ll break the build when I accidentally do something like
NSInteger code = …..;
NSLog(@“Closed with code %ld”, code);
which compiles fine for Mac OS, but causes an error on iOS:

/Couchbase/CouchbaseLite/Source/ChangeTracker/CBLWebSocketChangeTracker.m:256:78: error: values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead [-Werror,-Wformat]
        LogTo(ChangeTracker, @"%@: closed with code %ld, reason '%@'", self, effectiveCode, reason);
                                                    ~~~                      ^~~~~~~~~~~~~
                                                                             (long)

I’ve got the exact same warning flags enabled for both platforms. Is there a way I can enable this warning consistently in a build for any platform/word-size?

(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.)

—Jens
 _______________________________________________
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

  • Follow-Ups:
    • Re: -Wformat only warns about NSInteger as printf param in 32-bit builds
      • From: Quincey Morris <email@hidden>
    • Re: -Wformat only warns about NSInteger as printf param in 32-bit builds
      • From: Carl Hoefs <email@hidden>
  • Prev by Date: Re: Deleting a constraint just turns it grey
  • Next by Date: Re: -Wformat only warns about NSInteger as printf param in 32-bit builds
  • Previous by thread: Re: Deleting a constraint just turns it grey
  • Next by thread: Re: -Wformat only warns about NSInteger as printf param in 32-bit builds
  • Index(es):
    • Date
    • Thread