<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Structure size on VAX and ALPHA in Operating System - OpenVMS</title>
    <link>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596472#M7084</link>
    <description>Ram,&lt;BR /&gt;&lt;BR /&gt;Marc seems to have answered this question already.&lt;BR /&gt;&lt;BR /&gt;Please note that your code may pay a performance penalty, if you access data at non-aligned addresses. Sometimes the compiler can handle this, but sometimes it also happens at runtime, which is bad for performance on Alpha and really bad on Itanium (this is called alignment faults).&lt;BR /&gt;&lt;BR /&gt;Volker.</description>
    <pubDate>Thu, 04 Aug 2005 06:52:38 GMT</pubDate>
    <dc:creator>Volker Halle</dc:creator>
    <dc:date>2005-08-04T06:52:38Z</dc:date>
    <item>
      <title>Structure size on VAX and ALPHA</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596467#M7079</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;typedef struct {&lt;BR /&gt;    unsigned char length;                 &lt;BR /&gt;    unsigned char l2;                     &lt;BR /&gt;    char name[8];                         &lt;BR /&gt;    int num;                  &lt;BR /&gt;} l_s_r;&lt;BR /&gt;&lt;BR /&gt;I have the above declaration in a header file. and when i print the size of this structure&lt;BR /&gt;&lt;BR /&gt;&lt;QUOTE&gt;&lt;BR /&gt; printf("Size of structure l_s_r is : %d",sizeof(l_s_r)); &lt;BR /&gt;&lt;/QUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;i get 2 different values on ALPHA and VAX-&lt;BR /&gt;On ALPHA the size is shown as - 16 bytes&lt;BR /&gt;ON VAX the size is shown as - 14 bytes&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Interestingly the size of the below datatypes are same on both ALPHA and VAX.&lt;BR /&gt;unsigned char size is '1' byte                 &lt;BR /&gt;char size is '1' byte                         &lt;BR /&gt;int size is '4' byte     &lt;BR /&gt;    &lt;BR /&gt;&lt;BR /&gt;Then what could be reason for the difference in size of structure?</description>
      <pubDate>Thu, 04 Aug 2005 06:07:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596467#M7079</guid>
      <dc:creator>ram_47</dc:creator>
      <dc:date>2005-08-04T06:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Structure size on VAX and ALPHA</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596468#M7080</link>
      <description>Ram,&lt;BR /&gt;&lt;BR /&gt;alignment ?!&lt;BR /&gt;&lt;BR /&gt;On Alpha, that int num will probably be naturally aligned, i.e. aligned to the next longword address.&lt;BR /&gt;&lt;BR /&gt;Volker.</description>
      <pubDate>Thu, 04 Aug 2005 06:31:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596468#M7080</guid>
      <dc:creator>Volker Halle</dc:creator>
      <dc:date>2005-08-04T06:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Structure size on VAX and ALPHA</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596469#M7081</link>
      <description>Ram,&lt;BR /&gt;&lt;BR /&gt;look at qualifier member_alignment for the c-compiler.&lt;BR /&gt;You can try to compile with /nomember_ali and look at the effect.&lt;BR /&gt;&lt;BR /&gt;Rgds&lt;BR /&gt;Marc</description>
      <pubDate>Thu, 04 Aug 2005 06:47:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596469#M7081</guid>
      <dc:creator>Marc Van den Broeck</dc:creator>
      <dc:date>2005-08-04T06:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Structure size on VAX and ALPHA</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596470#M7082</link>
      <description>Volker,&lt;BR /&gt;&lt;BR /&gt;I did not really get what you are saying. Could you pl elaborate? Also, what is the solution to overcome this problem, because instead of reading 14 bytes my structure is reading 16 bytes and so my file pointer is positioned at a wrong place.</description>
      <pubDate>Thu, 04 Aug 2005 06:47:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596470#M7082</guid>
      <dc:creator>ram_47</dc:creator>
      <dc:date>2005-08-04T06:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Structure size on VAX and ALPHA</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596471#M7083</link>
      <description>ram,&lt;BR /&gt;&lt;BR /&gt;I agree with Volker. The alignment default in your two systems is different. Technically, to ensure that alignment is one way or the other, you need to use the #pragma [no]member_alignment C/C++ compiler directive.&lt;BR /&gt;&lt;BR /&gt;Typically, this #pragma is used with state save/restore code, as follows:&lt;BR /&gt;&lt;BR /&gt;#pragma member_alignment __save&lt;BR /&gt;#pragma [no]member_alignment&lt;BR /&gt;&lt;BR /&gt;{ code defining structures }&lt;BR /&gt;&lt;BR /&gt;#pragma member_alignment __restore&lt;BR /&gt;&lt;BR /&gt;You need to save/restore the current settings because different source sets may have differing presumptions, for a wide variety of reasons. Saving/restoring the member_alignment state allows your structure to be defined as needed, without impacting the rest of the compilation. &lt;BR /&gt;&lt;BR /&gt;For example, message formats for network messages are often packed by bytes, and use the nomember_alignment attribute. In memory data structures want the efficiency, and thus use the member_alignment attribute. &lt;BR /&gt;&lt;BR /&gt;- Bob Gezelter, &lt;A href="http://www.rlgsc.com" target="_blank"&gt;http://www.rlgsc.com&lt;/A&gt;</description>
      <pubDate>Thu, 04 Aug 2005 06:51:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596471#M7083</guid>
      <dc:creator>Robert Gezelter</dc:creator>
      <dc:date>2005-08-04T06:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: Structure size on VAX and ALPHA</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596472#M7084</link>
      <description>Ram,&lt;BR /&gt;&lt;BR /&gt;Marc seems to have answered this question already.&lt;BR /&gt;&lt;BR /&gt;Please note that your code may pay a performance penalty, if you access data at non-aligned addresses. Sometimes the compiler can handle this, but sometimes it also happens at runtime, which is bad for performance on Alpha and really bad on Itanium (this is called alignment faults).&lt;BR /&gt;&lt;BR /&gt;Volker.</description>
      <pubDate>Thu, 04 Aug 2005 06:52:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596472#M7084</guid>
      <dc:creator>Volker Halle</dc:creator>
      <dc:date>2005-08-04T06:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Structure size on VAX and ALPHA</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596473#M7085</link>
      <description>ram,&lt;BR /&gt;&lt;BR /&gt;  Alpha and Itanium compilers will add padding bytes to structure members in order to align them on "natural" boundaries. So, your structure has 2 single characters, followed by an 8 character string. That's 10 bytes. The compiler adds 2 bytes of padding so the integer starts on a longword boundary (multiple of 4).&lt;BR /&gt;&lt;BR /&gt;  The VAX compiler does not align structure members by default.&lt;BR /&gt;&lt;BR /&gt;  So you have a choice if you want the VAX and Alpha compilers to both lay out your structure in memory identically. You can:&lt;BR /&gt;&lt;BR /&gt; 1) force the compiler to omit the pad bytes and place the members exactly where you want them - this can be specified with a qualifier "/NOMEMBER_ALIGNMENT" to affect ALL structures, or selectively with a pragma "#pragma member_alignment".&lt;BR /&gt;&lt;BR /&gt; 2) rearrange your fields so they will be aligned without having to pad anything&lt;BR /&gt;&lt;BR /&gt; 3) add your own padding &lt;BR /&gt;&lt;BR /&gt;  Accesses to unaligned data is more expensive than accessing aligned data on all three architectures. It's moderate on VAX, bad on Alpha and VERY bad on Itanium.&lt;BR /&gt;&lt;BR /&gt;  Bob and Marc have suggested option 1, but you may be better off rearranging the fields to:&lt;BR /&gt;&lt;BR /&gt;typedef struct {&lt;BR /&gt;int num; &lt;BR /&gt;unsigned char length; &lt;BR /&gt;unsigned char l2; &lt;BR /&gt;char name[8]; &lt;BR /&gt;} l_s_r;&lt;BR /&gt;&lt;BR /&gt;  So, the int is naturally aligned with no need for padding. General rule is to declare quads, followed by longs, followed by short ints, then character strings. Remember that for most code the order of fields and extra padding shouldn't matter (some, myself included, would argue that code that does depend on field order is fundamentally broken and should be fixed!)&lt;BR /&gt;&lt;BR /&gt;  If you're somehow stuck with a misaligned record in a data file, I recommend defining two structures - the on disk structure and the in-memory structure. Hide the misaligned structure in your file access layer and move the fields into the aligned structure for processing. Even better, write a program to convert all your files into an aligned structure layout.</description>
      <pubDate>Thu, 04 Aug 2005 08:00:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596473#M7085</guid>
      <dc:creator>John Gillings</dc:creator>
      <dc:date>2005-08-04T08:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Structure size on VAX and ALPHA</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596474#M7086</link>
      <description>John,&lt;BR /&gt;&lt;BR /&gt;2 observations -&lt;BR /&gt;&lt;BR /&gt;1- rearranging the fields within the structure still returns me the wrong struct size. (returns me 16 bytes)&lt;BR /&gt;&lt;BR /&gt;2- enclosing the structure between the #pragma directive works! (returns me 14 bytes)</description>
      <pubDate>Fri, 05 Aug 2005 01:59:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/structure-size-on-vax-and-alpha/m-p/3596474#M7086</guid>
      <dc:creator>ram_47</dc:creator>
      <dc:date>2005-08-05T01:59:31Z</dc:date>
    </item>
  </channel>
</rss>

