<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ALeX Kazik &#187; int</title>
	<atom:link href="https://alex.kazik.de/tag/int/feed/" rel="self" type="application/rss+xml" />
	<link>https://alex.kazik.de</link>
	<description>A blog about Retrocomputing‎ and more</description>
	<lastBuildDate>Wed, 30 Mar 2022 09:54:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>Apples Integers</title>
		<link>https://alex.kazik.de/183/apples-integers/</link>
		<comments>https://alex.kazik.de/183/apples-integers/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 14:29:57 +0000</pubDate>
		<dc:creator><![CDATA[alx]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[LP64]]></category>
		<category><![CDATA[NSInteger]]></category>

		<guid isPermaLink="false">http://alex.kazik.de/?p=183</guid>
		<description><![CDATA[I was wondering whether I should use int, long or NSInteger. It took me a bit but I figured it out! On OS X and iOS the following table shows you the the size of the types: char 8 bit short 16 bit int 32 bit long system size long long 64 bit So, on [&#8230;]]]></description>
				<content:encoded><![CDATA[<p> I was wondering whether I should use <code>int</code>, <code>long</code> or <code>NSInteger</code>. It took me a bit but I figured it out!</p>
<p>On OS X and iOS the following table shows you the the size of the types:</p>
<pre>char       8 bit
short     16 bit
int       32 bit
long      system size
long long 64 bit</pre>
<p>So, on 32bit OS X <code>long</code> is 32 bit, on 64bit OS X it&#8217;s 64 bit (unsure for iOS).</p>
<p><code>NSInteger</code> has always the size of an pointer.</p>
<p>Often asked: &#8220;Use int or NSInteger?&#8221;. Answer: use <code>NSInteger</code> for pointers, ok usually you should use the pointer type itself, and for everything else use the size you require.</p>
<p>If you want exactly 8 bits, use <code>int8_t</code> for sigend or <code>uint8_t</code> for unsigned, for an integer which has at least those bits, use (<code>u</code>)<code>int_least8_t</code> (analogue for 16/32/64 bits).</p>
<p>Performance: you can use (<code>u</code>)<code>int_fast8_t</code> for the fastest type, which can hold (<code>u</code>)<code>int_8_t</code>. But since (u)int_leastY_t and (u)int_fastY_t are defined as (u)intY_t on OS X and iOS it should make no difference. I use the direct types for when all the bits are used, and the fast types when I don&#8217;t use exactly but less bits.</p>
<p>At last: don&#8217;t forget the <code>LL</code> or <code>ULL</code> suffix for 64bit constants (you can use (<code>U</code>)<code>INT64_C(num)</code> for always the correct suffix, also for 8/16/32), and the &#8220;%lld&#8221; in a formatted string for 64bit variables.<br />
(example: <code>NSLog(@"number: %lld", 1LL << 48);</code>)</p>
<p>If you have more information or maybe corrections, please post a comment.</p>]]></content:encoded>
			<wfw:commentRss>https://alex.kazik.de/183/apples-integers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
