<?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 - Operating Systems</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>Fri, 18 Jan 2008 11:01:51 GMT</pubDate>

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

<item>
    <title>Version Number Formatting</title>
    <link>http://portabilityblog.com/blog/archives/9-Version-Number-Formatting.html</link>
            <category>Operating Systems</category>
    
    <comments>http://portabilityblog.com/blog/archives/9-Version-Number-Formatting.html#comments</comments>
    <wfw:comment>http://portabilityblog.com/blog/wfwcomment.php?cid=9</wfw:comment>

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

    <author>nospam@example.com (Daniel Fischer)</author>
    <content:encoded>
    One thing that&#039;s biting me currently is imposed version number formatting. The product I&#039;m working on uses the traditional Major-Minor-Patch format, that is, there are three numerical components in a version number. Additionally, we add a suffix for special builds based on a previous release, such as a single letter for a hotfix build, or a service pack identifier, or a support ticket identifier.&lt;br /&gt;
&lt;br /&gt;
Getting software certified for Windows Vista necessitates including a manifest with the software that, among other information, contains the name of the executable, the version number, security settings, and a signature. The version number consists of four components: Major, minor, build and revision. The version number goes into an XML attribute, so one programmer apparently forgot to double-check and put in our regular three-component version number.&lt;br /&gt;
&lt;br /&gt;
Needless to say, we figured that out fairly fast, since Windows 2003 will refuse to run applications with embedded manifests that contain errors. Interestingly, the tool that actually embeds the manifest doesn&#039;t comment at all. And the error that you get from Windows is not very transparent - you have to look into the system event log to get a clue, and unless you&#039;re on Vista, the clue you&#039;re getting is only that there&#039;s &lt;i&gt;something&lt;/i&gt; wrong with your manifest. Anyway, we just added a zero as the fourth component and all was well.&lt;br /&gt;
&lt;br /&gt;
Over time, we started to use an 1 instead of a 0 as the fourth component for a revision based on a previous release.&lt;br /&gt;
&lt;br /&gt;
Some time later, we figured out that we actually have multiple different types of revisions. So now, the fourth component is calculated from all of them (or, all of those that we thought of, so far). It&#039;s starting to look like a bit field. Of course, the &quot;revision&quot; field is completely meaningless for comparison purposes: Revision 100 is based on completely different changes to the source code than Revision 1. Granted, you can still tell from revision 101 that it includes both sets of updates, but at this point I&#039;m just glad that our other platforms aren&#039;t as limiting. 
    </content:encoded>

    <pubDate>Fri, 18 Jan 2008 12:01:51 +0100</pubDate>
    <guid isPermaLink="false">http://portabilityblog.com/blog/archives/9-guid.html</guid>
    <category>vista</category>
<category>windows</category>

</item>
<item>
    <title>O_DIRECT</title>
    <link>http://portabilityblog.com/blog/archives/8-O_DIRECT.html</link>
            <category>Operating Systems</category>
    
    <comments>http://portabilityblog.com/blog/archives/8-O_DIRECT.html#comments</comments>
    <wfw:comment>http://portabilityblog.com/blog/wfwcomment.php?cid=8</wfw:comment>

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

    <author>nospam@example.com (Daniel Fischer)</author>
    <content:encoded>
    On UNIXoid operating systems, you can open(2) a file in many modes. On some operating systems, one of them is O_DIRECT, which stands for direct i/o without any caching. To sum it all up:&lt;br /&gt;
&lt;blockquote&gt;The whole notion of &quot;direct IO&quot; is totally braindamaged. Just say no. --&lt;a href=&quot;http://lkml.org/lkml/2007/1/10/233&quot;&gt;Linus Torvalds&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;
Accessing files that were opened with O_DIRECT requires aligned buffers for reading and writing. For example, on Linux 2.6, all buffers must be aligned to 512 bytes and reads and writes can only happen in multiples of 512 bytes. It&#039;s fairly easy to align your data to 512 bytes, though.&lt;br /&gt;
&lt;br /&gt;
On Linux 2.4, on the other hand, buffers have to be aligned to multiples of the underlying file system&#039;s logical block size - which is generally much larger than 512 bytes. Size also has to be a multiple of the block size. It&#039;s not so easy to solve this generally. It&#039;s also often forgotten because nobody wants to use Linux 2.4 anymore, at least not for development work.&lt;br /&gt;
&lt;br /&gt;
We ran into this problem at least three times in three different places in 2007. You can tell that I work for a database company.&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Fri, 28 Dec 2007 11:03:47 +0100</pubDate>
    <guid isPermaLink="false">http://portabilityblog.com/blog/archives/8-guid.html</guid>
    <category>linux</category>

</item>
<item>
    <title>socklen_t confusion</title>
    <link>http://portabilityblog.com/blog/archives/7-socklen_t-confusion.html</link>
            <category>Operating Systems</category>
    
    <comments>http://portabilityblog.com/blog/archives/7-socklen_t-confusion.html#comments</comments>
    <wfw:comment>http://portabilityblog.com/blog/wfwcomment.php?cid=7</wfw:comment>

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

    <author>nospam@example.com (Daniel Fischer)</author>
    <content:encoded>
    The BSD socket API (accept, bind, and so on) uses a struct sockaddr to pass socket addresses. Additionally, there&#039;s a parameter for passing the size of the memory block allocated for a struct sockaddr to the socket functions. This argument is passed as a pointer to the actual size, and upon completion of the API call, will contain the actual length of the address stored in the memory block instead of its size. In the original BSD API, this argument was of type int *.&lt;br /&gt;
&lt;br /&gt;
At one point, a draft of the POSIX.1g standard defined this to be size_t *. This was a bit broken because size_t is usually not the same type as int on 64-bit platforms, the re-definition thus resulting in an unintended and incompatible change. The short of it is that people complained, and the type was changed again. Instead of reverting to int *, however, a new type socklen_t was introduced. This new type is defined to be the same as int on most platforms. As Linus Torvalds puts it,&lt;br /&gt;
&lt;blockquote&gt;_Any_ sane library _must_ have &quot;socklen_t&quot; be the same size as int. Anything else breaks any BSD socket layer stuff. POSIX initially did make it a size_t, and I (and hopefully others, but obviously not too many) complained to them very loudly indeed. Making it a size_t is completely broken, exactly because size_t very seldom is the same size as &quot;int&quot; on 64-bit architectures, for example. And it has to be the same size as &quot;int&quot; because that&#039;s what the BSD socket interface is.&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
(Quote taken from man 2 accept on Linux.)&lt;br /&gt;
&lt;br /&gt;
So for a small period of time, operating system vendors were preparing for POSIX.1g as it was known back then and started to use size_t instead of int. As the draft was changed to use socklen_t, and later SUSv2 included socklen_t, they mostly started to use socklen_t and defined it to int. Some defined it to be the same type as size_t. One example that is mentioned in Linux&#039; man 2 accept is SunOS 5. This includes the current release of Solaris, being based on SunOS 5.10. However, that&#039;s not a &lt;i&gt;big&lt;/i&gt; portability issue. It&#039;s broken as described above, but code that uses socklen_t in all places should be just fine.&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you get the worst of both worlds. On the one hand, you can use the old BSD API with pointers to int. On the other hand, you can define _XOPEN_SOURCE_EXTENDED and get the new API with socklen_t. However, if you don&#039;t define _XOPEN_SOURCE_EXTENDED, you still get a definition of socklen_t to size_t.  The type exists but is completely worthless as it can&#039;t be used with the socket API, which expects int.&lt;br /&gt;
&lt;br /&gt;
I&#039;ve actually seen code that fell over this in both possible ways, using int * in one place and socklen_t * in another...&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Sat, 22 Dec 2007 14:22:00 +0100</pubDate>
    <guid isPermaLink="false">http://portabilityblog.com/blog/archives/7-guid.html</guid>
    <category>hp-ux</category>
<category>posix</category>

</item>
<item>
    <title>UNIX domain sockets</title>
    <link>http://portabilityblog.com/blog/archives/4-UNIX-domain-sockets.html</link>
            <category>Operating Systems</category>
    
    <comments>http://portabilityblog.com/blog/archives/4-UNIX-domain-sockets.html#comments</comments>
    <wfw:comment>http://portabilityblog.com/blog/wfwcomment.php?cid=4</wfw:comment>

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

    <author>nospam@example.com (Daniel Fischer)</author>
    <content:encoded>
    Unlike sockets in other domains, sockets in the UNIX domain are visible in the file system. Because of this, they&#039;re sometimes confused with regular files. When they&#039;re not being confused with regular files, their specific restrictions that don&#039;t apply to other files are still easily forgotten. One such restriction of a UNIX domain socket is the length of its name.&lt;br /&gt;
&lt;br /&gt;
Path names can be rather long on UNIX-like systems these days. Gone are the days of file names limited to 14 characters and for path names, POSIX-compliant operating systems generally support up to 256 characters. On many platforms, path names can be even longer than that. For example, PATH_MAX is 1024 on Mac OS X and 4096 on GNU/Linux. &lt;br /&gt;
&lt;br /&gt;
In contrast, the full path name of a UNIX domain socket must fit into a struct sockaddr_un. Its component sun_path generally has much less room for the socket&#039;s name than 1024 characters. Typical numbers are 108 (Linux, Solaris, Cygwin), 104 (AIX, BSDs, Mac OS X), and 92 (HP-UX). At some point, it was only 14 in &lt;a href=&quot;http://en.wikipedia.org/wiki/Interix&quot;&gt;Interix&lt;/a&gt; 5.2.&lt;br /&gt;
&lt;br /&gt;
This means that, while UNIX domain sockets do appear as if they were files, they can&#039;t be placed in an arbitrary location in the file system. Now, imagine an automated testing process that can test multiple instances of the software at a time, and keeps all files relevant to one test run within one directory. Path names can easily become longer than 92 characters in a scenario like this. In one case, this happened in a system where the name of one such instance&#039;s directory didn&#039;t have a constant length and occasionally brought the complete path to more than 92 characters, causing random total failures on HP-UX.  
    </content:encoded>

    <pubDate>Wed, 19 Dec 2007 12:05:00 +0100</pubDate>
    <guid isPermaLink="false">http://portabilityblog.com/blog/archives/4-guid.html</guid>
    <category>ipc</category>
<category>unix</category>

</item>
<item>
    <title>transparent_union</title>
    <link>http://portabilityblog.com/blog/archives/2-transparent_union.html</link>
            <category>Operating Systems</category>
    
    <comments>http://portabilityblog.com/blog/archives/2-transparent_union.html#comments</comments>
    <wfw:comment>http://portabilityblog.com/blog/wfwcomment.php?cid=2</wfw:comment>

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

    <author>nospam@example.com (Daniel Fischer)</author>
    <content:encoded>
    Let&#039;s say you&#039;re writing a function that accepts a pointer to an int.&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:#8f0055&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;do_stuff_with_int&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;p&lt;span style=&quot;color:#000000&quot;&gt;) {&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 2 &lt;/span&gt;  &lt;span style=&quot;color:#007f1c&quot;&gt;/* ... */&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 3 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Later, you notice that the doing stuff operation doesn&#039;t depend on signedness at all, and decide that you want to use your function with unsigned int too. Just passing a pointer to an unsigned int will cause a warning. How would you get rid of it in a clean way? Easy, use a union.&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:#8f0055&quot;&gt;typedef&lt;/span&gt; &lt;span style=&quot;color:#8f0055&quot;&gt;union&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 2 &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;si&lt;span style=&quot;color:#000000&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 3 &lt;/span&gt;  &lt;span style=&quot;color:#8f0055&quot;&gt;unsigned int&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;*&lt;/span&gt;ui&lt;span style=&quot;color:#000000&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 4 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;}&lt;/span&gt; signed_or_unsigned_int_pointer&lt;span style=&quot;color:#000000&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Now you have a type that can both contain a pointer to an int, or a pointer to an unsigned int. Wouldn&#039;t it be convenient if you could use your shiny new type to indicate that do_stuff_with_int() really can accept both types? That&#039;s where gcc&#039;s transparent_union attribute comes in. (Some other compilers also support this.)&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:#8f0055&quot;&gt;typedef&lt;/span&gt; &lt;span style=&quot;color:#8f0055&quot;&gt;union&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 2 &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;si&lt;span style=&quot;color:#000000&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 3 &lt;/span&gt;  &lt;span style=&quot;color:#8f0055&quot;&gt;unsigned int&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;*&lt;/span&gt;ui&lt;span style=&quot;color:#000000&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 4 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;}&lt;/span&gt; signed_or_unsigned_int_pointer
&lt;span style=&quot;color:#808080&quot;&gt; 5 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;__attribute__&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;((&lt;/span&gt;transparent_union&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:#808080&quot;&gt; 7 &lt;/span&gt;&lt;span style=&quot;color:#8f0055&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;do_stuff_with_int&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;(&lt;/span&gt;signed_or_unsigned_int_pointer p&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:#007f1c&quot;&gt;/* ... */&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 9 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt;10 &lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt;11 &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;12 &lt;/span&gt;  &lt;span style=&quot;color:#8f0055&quot;&gt;int&lt;/span&gt; a &lt;span style=&quot;color:#000000&quot;&gt;=&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;13 &lt;/span&gt;  &lt;span style=&quot;color:#8f0055&quot;&gt;unsigned int&lt;/span&gt; b &lt;span style=&quot;color:#000000&quot;&gt;=&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;14 &lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt;15 &lt;/span&gt;  &lt;span style=&quot;color:#000000&quot;&gt;do_stuff_with_int&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;(&amp;amp;&lt;/span&gt;a&lt;span style=&quot;color:#000000&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt;16 &lt;/span&gt;  &lt;span style=&quot;color:#000000&quot;&gt;do_stuff_with_int&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;(&amp;amp;&lt;/span&gt;b&lt;span style=&quot;color:#000000&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt;17 &lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt;18 &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;19 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Now, what&#039;s the catch? You can only use transparent_union with unions that contain only types with the same representation. In other words, they need to be the same size. You can&#039;t, for example, use it with a 32-bit int and a 64-bit integer, in which case gcc will generate a warning. And lots of errors later on, because you&#039;re not passing unions to your function, but any one of their constituent types, which isn&#039;t allowed without transparent_union.&lt;br /&gt;
&lt;br /&gt;
And now, the reason why this post is related to portability:&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:#8f0055&quot;&gt;typedef&lt;/span&gt; &lt;span style=&quot;color:#8f0055&quot;&gt;union&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 2 &lt;/span&gt;  &lt;span style=&quot;color:#8f0055&quot;&gt;int&lt;/span&gt; an_int&lt;span style=&quot;color:#000000&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 3 &lt;/span&gt;  &lt;span style=&quot;color:#8f0055&quot;&gt;long&lt;/span&gt; a_long&lt;span style=&quot;color:#000000&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 4 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;}&lt;/span&gt; int_union
&lt;span style=&quot;color:#808080&quot;&gt; 5 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;__attribute__&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;((&lt;/span&gt;transparent_union&lt;span style=&quot;color:#000000&quot;&gt;));&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
The transparent_union attribute will be ignored on most 64 bit platforms.&lt;br /&gt;
&lt;br /&gt;
Treating int and long as the same type is a beginner&#039;s mistake. But what about this code?&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:#8f0055&quot;&gt;typedef&lt;/span&gt; &lt;span style=&quot;color:#8f0055&quot;&gt;union&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;{&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 2 &lt;/span&gt;  &lt;span style=&quot;color:#8f0055&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color:#8f0055&quot;&gt;volatile&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;*&lt;/span&gt;i&lt;span style=&quot;color:#000000&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 3 &lt;/span&gt;  &lt;span style=&quot;color:#8f0055&quot;&gt;unsigned int&lt;/span&gt; &lt;span style=&quot;color:#8f0055&quot;&gt;volatile&lt;/span&gt; &lt;span style=&quot;color:#000000&quot;&gt;*&lt;/span&gt;u&lt;span style=&quot;color:#000000&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color:#808080&quot;&gt; 4 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;}&lt;/span&gt; int_union
&lt;span style=&quot;color:#808080&quot;&gt; 5 &lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;__attribute__&lt;/span&gt;&lt;span style=&quot;color:#000000&quot;&gt;((&lt;/span&gt;transparent_union&lt;span style=&quot;color:#000000&quot;&gt;));&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Should work, shouldn&#039;t it?&lt;br /&gt;
&lt;br /&gt;
Turns out it doesn&#039;t. That is, it works in most places. It even works on Mac OS X. Unless you build for the 64-bit PowerPC CPU. In that case, the attribute is ignored, even though the two types are still the same size. This only seems to happen on ppc64. On all three other architectures currently supported by Mac OS X, it works.&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;$ gcc -c t.c -arch ppc
&lt;span style=&quot;color:#808080&quot;&gt; 2 &lt;/span&gt;$ gcc -c t.c -arch ppc64
&lt;span style=&quot;color:#808080&quot;&gt; 3 &lt;/span&gt;t.c:6: warning: &#039;transparent_union&#039; attribute ignored
&lt;span style=&quot;color:#808080&quot;&gt; 4 &lt;/span&gt;$ gcc -c t.c -arch i386 
&lt;span style=&quot;color:#808080&quot;&gt; 5 &lt;/span&gt;$ gcc -c t.c -arch x86_64&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Sat, 15 Dec 2007 14:32:39 +0100</pubDate>
    <guid isPermaLink="false">http://portabilityblog.com/blog/archives/2-guid.html</guid>
    <category>gcc</category>
<category>mac os x</category>
<category>powerpc</category>

</item>

</channel>
</rss>