<?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: Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer in Operating System - OpenVMS</title>
    <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216582#M44115</link>
    <description>&lt;!--!*#--&gt;&amp;gt; (there r some warning during compiling, but&lt;BR /&gt;&amp;gt; I think it can be ignored)&lt;BR /&gt;&lt;BR /&gt;    foundKey = (UCHAR_PQ) 4599194146;&lt;BR /&gt;    x =        (UCHAR_PQ) 1;&lt;BR /&gt;&lt;BR /&gt;No complaints, same results.&lt;BR /&gt;&lt;BR /&gt;To _me_ it looks like a compiler bug, but&lt;BR /&gt;there could be some part of the C standard&lt;BR /&gt;for pointer arithmetic which I don't&lt;BR /&gt;understand.  It seems to do well enough with&lt;BR /&gt;8-byte integers.&lt;BR /&gt;&lt;BR /&gt;alp $ cc /version&lt;BR /&gt;HP C V7.3-009 on OpenVMS Alpha V7.3-2</description>
    <pubDate>Sat, 14 Jun 2008 13:56:36 GMT</pubDate>
    <dc:creator>Steven Schweda</dc:creator>
    <dc:date>2008-06-14T13:56:36Z</dc:date>
    <item>
      <title>Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216581#M44114</link>
      <description>&lt;!--!*#--&gt;Recently, we have a question, the codes is below:&lt;BR /&gt;(openvms v8.3, HP C v7.2, it happans both on I64 and AXP)&lt;BR /&gt;&lt;BR /&gt;/***** begin of codes ******/&lt;BR /&gt;#include "stdio.h"&lt;BR /&gt;#include "far_pointers.h"&lt;BR /&gt;&lt;BR /&gt;#pragma required_pointer_size save&lt;BR /&gt;#pragma required_pointer_size 64&lt;BR /&gt;&lt;BR /&gt;typedef unsigned char*       UCHAR_PQ;&lt;BR /&gt;&lt;BR /&gt;#pragma required_pointer_size restore&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;    UCHAR_PQ foundKey;&lt;BR /&gt;    UCHAR_PQ x;&lt;BR /&gt;    unsigned __int64 y;&lt;BR /&gt;    foundKey = 4599194146;&lt;BR /&gt;    x =        (unsigned __int64)1L;&lt;BR /&gt;    y = 1;&lt;BR /&gt;    printf("UCHAR_PQ x=%lld\n", x);&lt;BR /&gt;    printf("unsigned __int64 y=%lld\n", y);&lt;BR /&gt;    unsigned long recPos;&lt;BR /&gt;    printf("UCHAR_PQ foundKey:%lld\n", (UCHAR_PQ)foundKey);&lt;BR /&gt;    printf("foundKey-1:%lld\n", (unsigned __int64)(foundKey-1));&lt;BR /&gt;&lt;BR /&gt;/***** the line is the question *****/&lt;BR /&gt;    printf("foundKey-x:%lld\n", (unsigned __int64)(foundKey-x));&lt;BR /&gt;/*****                          *****/&lt;BR /&gt;&lt;BR /&gt;    printf("foundKey-y:%lld\n", (unsigned __int64)(foundKey-y));&lt;BR /&gt;    printf("foundKey-(unsigned __int64)x:%lld\n", (unsigned __int64)(foundKey-(unsigned __int64)x));&lt;BR /&gt;    printf("unsigned int64:%lld\n", (unsigned __int64)((unsigned __int64)foundKey-(unsigned __int64)x));&lt;BR /&gt;    printf("UCHAR_PQ size:%d\n", sizeof(UCHAR_PQ));&lt;BR /&gt;&lt;BR /&gt;    return 0;&lt;BR /&gt;}&lt;BR /&gt;/***** end of codes *****/&lt;BR /&gt;&lt;BR /&gt;compile, link and run it&lt;BR /&gt;(there r some warning during compiling, but I think it can be ignored)&lt;BR /&gt;&lt;BR /&gt;the result is &lt;BR /&gt;&lt;BR /&gt;UCHAR_PQ x=1&lt;BR /&gt;unsigned __int64 y=1&lt;BR /&gt;UCHAR_PQ foundKey:4599194146&lt;BR /&gt;foundKey-1:4599194145&lt;BR /&gt;foundKey-x:304226849&lt;BR /&gt;foundKey-y:4599194145&lt;BR /&gt;foundKey-(unsigned __int64)x:4599194145&lt;BR /&gt;unsigned int64:4599194145&lt;BR /&gt;UCHAR_PQ size:8&lt;BR /&gt;recPos = 9507089&lt;BR /&gt;&lt;BR /&gt;our question is :&lt;BR /&gt;&lt;BR /&gt;Why foundKey-x = 304226849, it should be 4599194145, I think&lt;BR /&gt;&lt;BR /&gt;we find:&lt;BR /&gt;304226849  =  0x12222221&lt;BR /&gt;4599194145 = 0x112222221&lt;BR /&gt;&lt;BR /&gt;that means :&lt;BR /&gt;64-bit pointer MINUS 64-bit pointer is 32-bit integer&lt;BR /&gt;&lt;BR /&gt;It is right or not?&lt;BR /&gt;&lt;BR /&gt;Please help me, thanks.&lt;BR /&gt;</description>
      <pubDate>Sat, 14 Jun 2008 05:35:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216581#M44114</guid>
      <dc:creator>Jingwei</dc:creator>
      <dc:date>2008-06-14T05:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216582#M44115</link>
      <description>&lt;!--!*#--&gt;&amp;gt; (there r some warning during compiling, but&lt;BR /&gt;&amp;gt; I think it can be ignored)&lt;BR /&gt;&lt;BR /&gt;    foundKey = (UCHAR_PQ) 4599194146;&lt;BR /&gt;    x =        (UCHAR_PQ) 1;&lt;BR /&gt;&lt;BR /&gt;No complaints, same results.&lt;BR /&gt;&lt;BR /&gt;To _me_ it looks like a compiler bug, but&lt;BR /&gt;there could be some part of the C standard&lt;BR /&gt;for pointer arithmetic which I don't&lt;BR /&gt;understand.  It seems to do well enough with&lt;BR /&gt;8-byte integers.&lt;BR /&gt;&lt;BR /&gt;alp $ cc /version&lt;BR /&gt;HP C V7.3-009 on OpenVMS Alpha V7.3-2</description>
      <pubDate>Sat, 14 Jun 2008 13:56:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216582#M44115</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-06-14T13:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216583#M44116</link>
      <description>Hi, Steven Schweda&lt;BR /&gt;&lt;BR /&gt;Thank you for your reply&lt;BR /&gt;&lt;BR /&gt;I also think it may be a bug.&lt;BR /&gt;</description>
      <pubDate>Sat, 14 Jun 2008 14:08:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216583#M44116</guid>
      <dc:creator>Jingwei</dc:creator>
      <dc:date>2008-06-14T14:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216584#M44117</link>
      <description>&amp;gt;alp $ cc /version&lt;BR /&gt;&amp;gt;HP C V7.3-009 on OpenVMS Alpha V7.3-2&lt;BR /&gt;&lt;BR /&gt;It means you had tested it in HP C V7.3, doesn't it?&lt;BR /&gt;&lt;BR /&gt;If yes, then thank you again, I just planed to find the newest compiler and test it :)</description>
      <pubDate>Sat, 14 Jun 2008 14:11:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216584#M44117</guid>
      <dc:creator>Jingwei</dc:creator>
      <dc:date>2008-06-14T14:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216585#M44118</link>
      <description>Ah, C, my old friend.  Moving stuff between different-sized variables and signed and unsigned variables can have some very unexpected results; variable promotion and demotion is an obscure corner of C.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://h71000.www7.hp.com/commercial/c/docs/6180profile_018.html#index_x_663" target="_blank"&gt;http://h71000.www7.hp.com/commercial/c/docs/6180profile_018.html#index_x_663&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Here's a local test run with some updated and tweaked code...&lt;BR /&gt;&lt;BR /&gt;$ cc /version&lt;BR /&gt;HP C V7.3-009 on OpenVMS Alpha V7.3-2  &lt;BR /&gt;$ cc x/pointer=long&lt;BR /&gt;$ link x&lt;BR /&gt;$ r x&lt;BR /&gt;UCHAR_PQ x=1&lt;BR /&gt;unsigned __int64 y=1&lt;BR /&gt;UCHAR_PQ foundKey:4599194146&lt;BR /&gt;foundKey-1:4599194145&lt;BR /&gt;foundKey-x:4599194145&lt;BR /&gt;foundKey-y:4599194145&lt;BR /&gt;foundKey-(unsigned long long)x:4599194145&lt;BR /&gt;unsigned int64:4599194145&lt;BR /&gt;UCHAR_PQ size:8&lt;BR /&gt;$ &lt;BR /&gt;&lt;BR /&gt;Bugfixes and corrections below:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;FAR_POINTERS.H&gt;&lt;BR /&gt;&lt;BR /&gt;#pragma required_pointer_size save&lt;BR /&gt;#pragma required_pointer_size 64&lt;BR /&gt;&lt;BR /&gt;typedef unsigned char*       UCHAR_PQ;&lt;BR /&gt;&lt;BR /&gt;#pragma required_pointer_size restore&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;    UCHAR_PQ foundKey;&lt;BR /&gt;    UCHAR_PQ x;&lt;BR /&gt;    unsigned long long y;&lt;BR /&gt;    foundKey = (void *) 4599194146UL;&lt;BR /&gt;    x =        (UCHAR_PQ) (unsigned long long *)1UL;&lt;BR /&gt;    y = 1;&lt;BR /&gt;    printf("UCHAR_PQ x=%lld\n", x);&lt;BR /&gt;    printf("unsigned __int64 y=%lld\n", y);&lt;BR /&gt;    unsigned long recPos;&lt;BR /&gt;    printf("UCHAR_PQ foundKey:%lld\n", (UCHAR_PQ)foundKey);&lt;BR /&gt;    printf("foundKey-1:%lld\n", (unsigned long long)(foundKey-1));&lt;BR /&gt;&lt;BR /&gt;/***** the line is the question *****/&lt;BR /&gt;    printf("foundKey-x:%lld\n", (unsigned long long)(foundKey-(unsigned long long) x));&lt;BR /&gt;/*****                          *****/&lt;BR /&gt;&lt;BR /&gt;    printf("foundKey-y:%lld\n", (unsigned long long)(foundKey-y));&lt;BR /&gt;    printf("foundKey-(unsigned long long)x:%lld\n", (unsigned long long)(foundKey-(unsigned long long)x));&lt;BR /&gt;    printf("unsigned int64:%lld\n", (unsigned __int64)((unsigned long long)foundKey-(unsigned long long)x));&lt;BR /&gt;    printf("UCHAR_PQ size:%d\n", sizeof(UCHAR_PQ));&lt;BR /&gt;&lt;BR /&gt;    return EXIT_SUCCESS;&lt;BR /&gt;}&lt;BR /&gt;&lt;/FAR_POINTERS.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Sat, 14 Jun 2008 14:22:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216585#M44118</guid>
      <dc:creator>Hoff</dc:creator>
      <dc:date>2008-06-14T14:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216586#M44119</link>
      <description>This surprised me as well.&lt;BR /&gt;The test programs is nice an comprehensive, and shows the workaround. Thanks. What I tend to do to figure out these problems without actually running code is to &lt;BR /&gt;$CC/NOOPT/LIST/MACHINE.&lt;BR /&gt;To wit:&lt;BR /&gt;&lt;BR /&gt;original:&lt;BR /&gt; printf ... (unsigned __int64)(foundKey-x));&lt;BR /&gt;&lt;BR /&gt;SUBQ    foundKey, x, R0 &lt;BR /&gt;SEXTL   R0, R17&lt;BR /&gt;&lt;BR /&gt;Workaround:&lt;BR /&gt; printf ... (unsigned __int64) foundKey -  (unsigned __int64) x );&lt;BR /&gt;&lt;BR /&gt;SUBQ    foundKey, x, R17 &lt;BR /&gt;&lt;BR /&gt;This workaround is hinted to be the DEC C User Guide: "1.7.5 Avoiding Problems"&lt;BR /&gt;" â ¢ Do bit manipulation on unsigned int and unsigned _ _int64, and carefully&lt;BR /&gt;cast pointers to and from them.&lt;BR /&gt;"&lt;BR /&gt;&lt;BR /&gt;The origin of the trouble is probably best described in :&lt;BR /&gt;&lt;BR /&gt;The DEC-C language reference manual gives a hint in "6.5.2 Additive Operators:&lt;BR /&gt;"When two pointers to elements of the same array are subtracted, the result&lt;BR /&gt;(calculated by dividing the difference between the two addresses by the length&lt;BR /&gt;of one element) is of type ptrdiff_t, which in HP C is int, and represents&lt;BR /&gt;the number of elements between the two addressed elements. If the two&lt;BR /&gt;elements are not in the same array, the result of this operation is undefined."&lt;BR /&gt;&lt;BR /&gt;So it seems pointer aritmetic is only valid within the same, 32 bit, array space.&lt;BR /&gt;&lt;BR /&gt;Also see:&lt;BR /&gt;&lt;BR /&gt;Referenence manual:&lt;BR /&gt;"B.23 Additive Operators (Â§3.3.6)&lt;BR /&gt;Pointers to members of the same array can be subtracted. The result is the&lt;BR /&gt;number of elements between the two array members. The type of the result is&lt;BR /&gt;ptrdiff_t. HP C defines this type as int."&lt;BR /&gt;&lt;BR /&gt;And see: stddef.h&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 14 Jun 2008 15:36:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216586#M44119</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-06-14T15:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216587#M44120</link>
      <description>&amp;gt; It means you had tested it in HP C V7.3,&lt;BR /&gt;&amp;gt; doesn't it?&lt;BR /&gt;&lt;BR /&gt;Yes.  V7.3-009.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; [...] B.23 Additive Operators [...]&lt;BR /&gt;&lt;BR /&gt;As I said, "[...] there could be [...]".&lt;BR /&gt;Everything's complicated.&lt;BR /&gt;&lt;BR /&gt;You can usually find an up-to-date compiler&lt;BR /&gt;on a TestDrive system, too, although the&lt;BR /&gt;Alphas are gone now:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.testdrive.hp.com/" target="_blank"&gt;http://www.testdrive.hp.com/&lt;/A&gt;</description>
      <pubDate>Sat, 14 Jun 2008 17:10:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216587#M44120</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-06-14T17:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216588#M44121</link>
      <description>&amp;gt;Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer&lt;BR /&gt;&lt;BR /&gt;Yes, I've heard that can be the case and someone pointed to Alpha.  The Standard says the result of a pointer difference is a ptrdiff_t.  In C99 a pointer fits in an intptr_t.&lt;BR /&gt;&lt;BR /&gt;On HP-UX, a ptrdiff_t is a long, either 32 (ILP32) or 64 bit (LP64).&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Hein: So it seems pointer arithmetic is only valid within the same, 32 bit, array space.&lt;BR /&gt;&lt;BR /&gt;Yes, the Standard says it is only valid in the same array.  It seems that Tru64/OVMS never did its huge data roll like we did on HP-UX, where everything can be 64 bit.  (With still some limitations on locals and parms.)</description>
      <pubDate>Sun, 15 Jun 2008 03:32:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216588#M44121</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-06-15T03:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216589#M44122</link>
      <description>Hi, All&lt;BR /&gt;&lt;BR /&gt;Thank you very much.&lt;BR /&gt;&lt;BR /&gt;I should read the books more carefully :)&lt;BR /&gt;&lt;BR /&gt;So, thank Hein again :)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Eh... it should not be called a "bug". But I hope it can be "fixed" :)&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 15 Jun 2008 14:10:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216589#M44122</guid>
      <dc:creator>Jingwei</dc:creator>
      <dc:date>2008-06-15T14:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Is it right that 64-bit pointer MINUS 64-bit pointer IS 32-bit integer</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216590#M44123</link>
      <description>My Plauger/Brodie ANSI C reference says subtraction of pointers is only valid if both pointer's values are addresses of elements of the same array (or 1 element past the last) and the result is of type ptrdiff_t (a signed integer type defined in stddef.h).</description>
      <pubDate>Sun, 15 Jun 2008 20:31:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/is-it-right-that-64-bit-pointer-minus-64-bit-pointer-is-32-bit/m-p/4216590#M44123</guid>
      <dc:creator>David Jones_21</dc:creator>
      <dc:date>2008-06-15T20:31:13Z</dc:date>
    </item>
  </channel>
</rss>

