objective c - Why does an NSInteger variable have to be cast to long when used as a format argument? -


nsinteger myint = 1804809223; nslog(@"%i", myint); <====  

the code above produces error:

values of type "nsinteger" should not used format arguments: add explicit cast 'long' instead. 

the correct nslog message nslog(@"%lg", (long) myint); why have convert integer value of myint long if want value display?

you warning if compile on os x (64-bit), because on platform nsinteger defined long , 64-bit integer. %i format, on other hand, int, 32-bit. format , actual parameter not match in size.

since nsinteger 32-bit or 64-bit, depending on platform, compiler recommends add cast long generally.

update: since ios 7 supports 64-bit well, can same warning when compiling ios.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -