<p><code>NSInteger</code>/<code>NSUInteger</code> are Cocoa-defined replacements for the regular built-in types.</p>

<p>Is there any benefit to using the NS* types over the built-ins? Which do you prefer and why? Are <code>NSInteger</code> and <code>int</code> the same width on 32-bit / 64-bit platforms?</p>

[{'answer_id': 13730, 'author': 'Sören Kuklau', 'author_id': 1600, 'author_profile': 'https://Stackoverflow.com/users/1600', 'pm_score': 4, 'selected': False, 'text': '<p>64-bit is actually the raison d\'être for NSInteger and NSUInteger; before 10.5, those did not exist. The two are simply defined as longs in 64-bit, and as ints in 32-bit:</p>\n\n<pre><code>#if __LP64__ || NS_BUILD_32_LIKE_64\ntypedef long NSInteger;\ntypedef unsigned long NSUInteger;\n#else\ntypedef int NSInteger;\ntypedef unsigned int NSUInteger;\n#endif\n</code></pre>\n\n<p>Thus, using them in place of the more basic C types when you want the \'bit-native\' size.</p>\n\n<p><a href="http://web.archive.org/web/20120206001941/http://www.cocoadev.com/index.pl?NSUInteger" rel="nofollow noreferrer">CocoaDev has some more info.</a></p>\n'}, {'answer_id': 13742, 'author': 'Theo', 'author_id': 1109, 'author_profile': 'https://Stackoverflow.com/users/1109', 'pm_score': 7, 'selected': True, 'text': "<p>The way I understand it is that NSInteger et al. are architecture safe versions of the corresponding C types. Basically their size vary depending on the architecture, but NSInteger, for example, is guaranteed to hold any valid pointer for the current architecture.</p>\n\n<p>Apple recommends that you use these to work with OS X 10.5 and onwards, and Apple's API:s will use them, so it's definitely a good idea to get into the habit of using them. They require a little more typing, but apart from that it doesn't seem to be any reason not to use them.</p>\n"}, {'answer_id': 13774, 'author': 'JamesSugrue', 'author_id': 1075, 'author_profile': 'https://Stackoverflow.com/users/1075', 'pm_score': 0, 'selected': False, 'text': "<p>I prefer the standard c style declarations but only because I switch between several languages and I don't have to think too much about it but sounds like I should start looking at nsinteger</p>\n"}, {'answer_id': 199472, 'author': 'mmalc', 'author_id': 23233, 'author_profile': 'https://Stackoverflow.com/users/23233', 'pm_score': 5, 'selected': False, 'text': '<h2>Quantisation issues for 64-bit runtime</h2>\n\n<p>In some situations there may be good reason to use standard types instead of <code>NSInteger</code>: "unexpected" memory bloat in a 64-bit system.</p>\n\n<p>Clearly if an integer is 8 instead of 4 bytes, the amount of memory taken by values is doubled. Given that not every value is an integer, though, you should typically not expect the memory footprint of your application to double.  However, the way that Mac OS X allocates memory changes depending on the amount of memory requested.</p>\n\n<p>Currently, if you ask for 512 bytes or fewer, <code>malloc</code> rounds up to the next multiple of 16 bytes.  If you ask for more than 512 bytes, however, <code>malloc</code> rounds up to the next multiple of 512 (at least 1024 bytes). Suppose then that you define a class that -- amongst others -- declares five <code>NSInteger</code> instance variables, and that on a 32-bit system each instance occupies, say, 272 bytes.  On a 64-bit system, instances would in theory require 544 bytes.  But, because of the memory allocation strategy, each will actually occupy 1024 bytes (an almost fourfold increase).  If you use a large number of these objects, the memory footprint of your application may be considerably greater than you might otherwise expect. If you replaced the <code>NSInteger</code> variables with <code>sint_32</code> variables, you would only use 512 bytes.</p>\n\n<p>When you\'re choosing what scalar to use, therefore, make sure you choose something sensible. Is there any reason why you need a value greater than you needed in your 32-bit application?  Using a 64-bit integer to count a number of seconds is unlikely to be necessary...</p>\n'}, {'answer_id': 10221308, 'author': 'Jason Fuerstenberg', 'author_id': 869287, 'author_profile': 'https://Stackoverflow.com/users/869287', 'pm_score': 0, 'selected': False, 'text': '<p>For importing and exporting data to files or over the net I use <strong>UInt32</strong>, <strong>SInt64</strong> etc...</p>\n\n<p>These are guaranteed to be of a certain size regardless of the architecture and help in porting code to other platforms and languages which also share those types.</p>\n'}]
['https://Stackoverflow.com/questions/13725', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1043/']