-Wformat only warns about NSInteger as printf param in 32-bit builds
-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