<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Portability Blog (Entries tagged as visual studio)</title>
    <link>http://portabilityblog.com/blog/</link>
    <description>tales about building software on many platforms</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.2.1 - http://www.s9y.org/</generator>
    <managingEditor>df.portabilityblog@erinye.com</managingEditor>
<webMaster>df.portabilityblog@erinye.com</webMaster>
<pubDate>Sun, 16 Dec 2007 10:00:00 GMT</pubDate>

    <image>
        <url>http://portabilityblog.com/blog/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Portability Blog - tales about building software on many platforms</title>
        <link>http://portabilityblog.com/blog/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>sizeof(long)</title>
    <link>http://portabilityblog.com/blog/archives/3-sizeoflong.html</link>
            <category>Compilers</category>
    
    <comments>http://portabilityblog.com/blog/archives/3-sizeoflong.html#comments</comments>
    <wfw:comment>http://portabilityblog.com/blog/wfwcomment.php?cid=3</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://portabilityblog.com/blog/rss.php?version=2.0&amp;type=comments&amp;cid=3</wfw:commentRss>
    

    <author>nospam@example.com (Daniel Fischer)</author>
    <content:encoded>
    It should be an offense to rely on the size of a given type in C to be the same across different platforms. Still, certain assumptions appear to be fairly common. One of them is the value of sizeof(long). I think we&#039;ve gotten over the idea that long and int are the same size now that 64 bit platforms are becoming more and more common. However, occassionally I still encounter a similar misconception: That the sizes of long and any pointer type are the same.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;font-size:9pt;&quot;&gt;&lt;span style=&quot;color:#808080&quot;&gt; 1 &lt;/span&gt;&lt;span style=&quot;color:#733710&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 2 &lt;/span&gt;&lt;span style=&quot;color:#733710&quot;&gt;#define S(X) printf(#X&lt;/span&gt; &lt;span style=&quot;color:#733710&quot;&gt;&amp;quot; %d&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color:#733710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#733710&quot;&gt;, sizeof(X))&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 3 &lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 4 &lt;/span&gt;&lt;span style=&quot;color:#8f0055&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;() {&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 5 &lt;/span&gt;  &lt;span style=&quot;color:#000000&quot;&gt;S&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#8f0055&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;*);&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 6 &lt;/span&gt;  &lt;span style=&quot;color:#000000&quot;&gt;S&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#8f0055&quot;&gt;long&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 7 &lt;/span&gt;  &lt;span style=&quot;color:#8f0055&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color:#2300ff&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 8 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
This snippet will tell you that both a long and a pointer to int are of size 4 on most 32 bit platforms, and that both are of size 8 on most 64 bit platforms. There is one notable platform where this isn&#039;t the case. When compiled with Visual Studio&#039;s cl.exe on 64 bit Windows, the size of the pointer will be 8, but the size of the long will be 4.&lt;br /&gt;
&lt;br /&gt;
According to the C standard, this is perfectly legal. In reality, I&#039;ve seen variables of type long used to store pointers, or anything else that fits into a long on one of the other platforms. Please stop doing that, it&#039;s wrong, and it will break on Windows. 
    </content:encoded>

    <pubDate>Sun, 16 Dec 2007 11:00:00 +0100</pubDate>
    <guid isPermaLink="false">http://portabilityblog.com/blog/archives/3-guid.html</guid>
    <category>64 bit</category>
<category>visual studio</category>
<category>windows</category>

</item>

</channel>
</rss>