ios - "NSString stringWithFormat:" with "%zd" curious behavior in 32bit devices -


why cannot format string using "%zd" expected in 32bit devices(iphone5, iphone4s or simulators)?

int64_t test1 = 13244212; int64_t test2 = 23244212; int64_t test3 = 33244212; int64_t test4 = 43244212; nsstring *teststr = [nsstring stringwithformat:@"\"%zd %zd %zd %zd\"", test1, test2, test3, test4]; nslog(@"teststr: %@", teststr);  nsinteger test5 = 53244212; nsinteger test6 = 63244212; nsinteger test7 = 73244212; nsinteger test8 = 83244212; teststr = [nsstring stringwithformat:@"\"%zd %zd %zd %zd\"", test5, test6, test7, test8]; nslog(@"teststr: %@", teststr); 

the log is:

2017-09-12 05:53:59.462: teststr:"11111111 0 22222222 0" 2017-09-12 05:53:59.465: teststr:"55555555 66666666 77777777 88888888" 

note: answer typed in on tablet, sample not tested, guess.

the format %zd values of type size_t , not 64-bit values.

try using %lld int64_t values, long long 64 bits on both 32-bit , 64-bit ios versions.

for nsinteger try %ld , cast arguments long, because size of nsinteger dependent on platform.

hth


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -