{"id":85,"date":"2008-04-18T22:06:30","date_gmt":"2008-04-18T14:06:30","guid":{"rendered":"http:\/\/blog.urdada.net\/2008\/04\/18\/85\/"},"modified":"2019-02-10T01:44:05","modified_gmt":"2019-02-09T17:44:05","slug":"%e4%b8%80%e5%80%8b%e9%95%b7%e6%95%b4%e6%95%b8%e5%90%84%e8%87%aa%e8%a1%a8%e8%bf%b0-on-64-bit-system","status":"publish","type":"post","link":"https:\/\/dada.tw\/blog\/2008\/04\/18\/85\/","title":{"rendered":"\u4e00\u500b\u9577\u6574\u6578\u5404\u81ea\u8868\u8ff0 (in 64-bit system)"},"content":{"rendered":"<p>Size of long integer may be different between 64-bit systems (\u4e00\u500b\u9577\u6574\u6578\u5404\u81ea\u8868\u8ff0)<\/p>\n<p>\u4e0d\u77e5\u9053\u662f\u4e0d\u662f\u6211\u592a\u843d\u4f0d\u4e86&#8230;<\/p>\n<p>\u6211\u4e00\u76f4\u4ee5\u70ba C\/C++ \u4e0b\u9762 short, long, long long \u4e09\u7a2e\u8cc7\u6599\u578b\u614b\u90fd\u56fa\u5b9a\u662f 2, 4, 8 \u500b bytes \u5927\u5c0f\u3002\u53ea\u6709 int \u9019\u500b\u8cc7\u6599\u578b\u614b\u6703\u56e0\u70ba 16-bit\/32-bit \u7cfb\u7d71\u7684\u4e0d\u540c\u800c\u8b8a\u6210 2 \u6216 4 bytes \u7684\u5927\u5c0f\uff0c\u6240\u4ee5\u7406\u6240\u7576\u7136 int \u5728 64-bit \u7684\u96fb\u8166\u4e5f\u61c9\u8a72\u6703\u8b8a\u6210 8 bytes (64-bit) \u7684\u5927\u5c0f\u56c9 ?!<\/p>\n<p>\u5728\u6574\u7406\u524d\u4e00\u7bc7\u6587\u7ae0\u300a<a href=\"https:\/\/dada.tw\/2008\/04\/18\/84\/\" target=\"_blank\">Bypass the 2GB file size limit on 32-bit Linux<\/a>\u300b\u7684\u6642\u5019\uff0c\u8b93\u6211\u9a5a\u89ba\u5728 64-bit \u7684\u7cfb\u7d71\u4e0b\uff0clong \u7684\u9577\u5ea6\u4e5f\u662f\u5404\u81ea\u8868\u8ff0\u7684\uff01<\/p>\n<p>\u9996\u5148\uff0cint \u7684\u5927\u5c0f\u5373\u4f7f\u5230\u4e86 64-bit \u7684\u6a5f\u5668\u4e0a\uff0c\u5927\u90e8\u5206\u7684\u7cfb\u7d71\u4ecd\u7136\u4f7f\u7528 4 bytes \u7684\u5927\u5c0f\u800c\u5df2\uff0c\u9019\u4e3b\u8981\u662f\u70ba\u4e86\u907f\u514d\u7a0b\u5f0f\u5f9e 32-bit \u7cfb\u7d71\u8f49\u63db\u5230 64-bit \u7cfb\u7d71\u9700\u8981\u4fee\u6539\u592a\u591a\u5730\u65b9<\/p>\n<p>\u518d\u4f86\uff0c\u8acb\u53c3\u8003 Wikipedia: <a href=\"http:\/\/en.wikipedia.org\/wiki\/64-bit#64-bit_data_models\" target=\"_blank\">64-bit data models<\/a> \u7684\u8aaa\u660e<\/p>\n<p>\u7d55\u5927\u591a\u6578\u7684 UNIX \u7cfb\u7d71\u5728 64-bit \u4e0b\u9762\u63a1\u7528 <a href=\"http:\/\/www.unix.org\/version2\/whatsnew\/lp64_wp.html\" target=\"_blank\">LP64<\/a> \u9019\u7a2e data model\uff0c\u9019\u6642\u5019 long \u5c31\u4e0d\u518d\u662f\u56fa\u5b9a\u70ba 4 bytes \u5927\u5c0f\uff0c\u800c\u662f\u8b8a\u6210 8 bytes \u7684\u5927\u5c0f\u4e86\uff01<\/p>\n<p>\u7136\u800c\uff0cWin64 \u537b\u4e0d\u662f\u4f7f\u7528 LP64\uff0c\u800c\u662f\u63a1\u7528 LLP64 \u9019\u500b data model\uff0c\u9019\u6642\u5019 long \u7684\u5927\u5c0f\u4ecd\u7136\u9084\u662f 4 bytes<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/farm4.static.flickr.com\/3219\/2422521769_4f4c50c2f2.jpg?w=625\"><\/p>\n<p><strong><i>Many 64-bit compilers today use the <strong>LP64<\/strong> model (including Solaris, AIX, HP, Linux, Mac OS X, and IBM z\/OS native compilers). Microsoft&#8217;s VC++ compiler uses the <strong>LLP64<\/strong> model.<\/i><\/strong><\/p>\n<p>\u5169\u7a2e data model \u7684\u6700\u5927\u5dee\u7570\u9ede\u5c31\u662f long \u9019\u500b\u8cc7\u6599\u578b\u614b\u7684\u5927\u5c0f\uff0cLP64 \u662f 64-bit\uff0c\u800c LLP64 \u5247\u662f 32-bit<\/p>\n<p>LLP64 data model \u57fa\u672c\u4e0a\u53ef\u4ee5\u8aaa\u8ddf 32-bit \u7684\u7cfb\u7d71\u4e00\u6a23\uff0c\u552f\u4e00\u5dee\u5225\u53ea\u6709\u4f4d\u5740(pointer)\u6539\u6210\u4e86 64-bit \u800c\u5df2\u3002\u8cc7\u6599\u7269\u4ef6(class, structure) \u7b49\u5982\u679c\u6c92\u6709\u5305\u542b pointer \u7684\u6210\u54e1\u7684\u8a71\uff0c\u6574\u500b\u7269\u4ef6\u7684\u5927\u5c0f\u662f\u8207 32-bit \u7cfb\u7d71\u4e00\u6a23\u7684\uff01<\/p>\n<p>\u800c LP64 \u5247\u662f\u9664\u4e86\u4f4d\u5740(pointer)\u6539\u6210 64-bit \u4e4b\u5916\uff0clong \u7684\u5927\u5c0f\u4e5f\u8b8a\u6210\u4e86 64-bit \u5927\u5c0f\u3002\u6240\u4ee5\u5728 UNIX \u4e0b\u9762\uff0c\u8981\u628a 32-bit \u7a0b\u5f0f porting \u5230 64-bit \u53ef\u80fd\u8981\u6bd4 Windows \u591a\u82b1\u8cbb\u591a\u4e00\u9ede\u529f\u592b\u3002<\/p>\n<p>\u6240\u4ee5\u5462\uff0c\u6211\u5011\u89c0\u5bdf\u5230\u5169\u500b\u554f\u984c\u5f71\u97ff\u8457\u7a0b\u5f0f\u7684\u76f8\u5bb9\u6027<\/p>\n<ol>\n<li>\u5728 UNIX \u4e0b\u9762\uff0clong \u7684\u5927\u5c0f\u5728 32-bit \u8207 64-bit \u7684\u7cfb\u7d71\u4e0b\u662f\u4e0d\u4e00\u6a23\u7684<\/li>\n<li>\u540c\u6a23\u662f 64-bit \u7cfb\u7d71\uff0cUNIX \u8207 Windows \u5c0d\u65bc long \u7684\u5927\u5c0f\u770b\u6cd5\u662f\u4e0d\u4e00\u81f4\u7684<\/li>\n<\/ol>\n<p>\u70ba\u4e86\u4f7f\u7a0b\u5f0f\u5728 32-bit \u8207 64-bit \u4e4b\u9593\u4ee5\u53ca UNIX \u8207 Windows \u4e4b\u9593\u7684\u76f8\u5bb9\u6027\u63d0\u6607\uff0c\u6539\u7528\u56fa\u5b9a\u9577\u5ea6\u7684\u8cc7\u6599\u578b\u614b\u662f\u5beb\u7a0b\u5f0f\u7684\u4e00\u500b\u597d\u7fd2\u6163<\/p>\n<p>\u5728 UNIX \u4e0b\u9762\uff0c\u6211\u5011\u53ef\u4ee5\u6539\u7528 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Stdint.h\" target=\"_blank\">stdint.h<\/a> \u9019\u500b header file \u4e2d\u5c0d\u65bc\u8cc7\u6599\u578b\u614b\u7684\u5b9a\u7fa9:<\/p>\n<pre>int8_t     8-bit signed interger\nint16_t    16-bit signed interger\nint32_t    32-bit signed interger\nint64_t    64-bit signed interger\nuint8_t    8-bit unsigned interger\nuint16_t   16-bit unsigned interger\nuint32_t   32-bit unsigned interger\nuint64_t   64-bit unsigned interger\n<\/pre>\n<p>\u5728 Windows \u4e0b\u9762\uff0c\u5247\u6539\u7528\u4e0b\u9762\u9019\u4e9b\u6574\u6578\u56fa\u5b9a\u5927\u5c0f\u7684\u8cc7\u6599\u578b\u614b<\/p>\n<pre>INT8       8-bit signed integer\nINT16      16-bit signed integer\nINT32      32-bit signed integer\nINT64      64-bit signed integer\nUINT8      8-bit unsigned integer\nUINT16     16-bit unsigned integer\nUINT32     32-bit unsigned integer\nUINT64     64-bit unsigned integer\n<\/pre>\n<p>\u7d55\u5c0d\u4e0d\u8981\u518d\u4f7f\u7528 int \u548c long \u4e86\uff01<\/p>\n<p>\u5c24\u5176\u662f\u5beb\u7db2\u8def\u7a0b\u5f0f\u6642\uff0c\u5f88\u53ef\u80fd client \u662f Windows \u800c server \u662f UNIX\uff0c\u7136\u5f8c\u53c8\u6709 32-bit \u53ca 64-bit \u7cfb\u7d71\u6df7\u5728\u88e1\u9762\uff0c\u4e00\u4e0d\u5c0f\u5fc3\u5c31\u767c\u751f\u4e0d\u76f8\u5bb9\u7684\u554f\u984c\u4e86&#8230;<\/p>\n<p>\u7576\u7136\uff0c\u5728 64-bit \u7684\u7cfb\u7d71\u4e0b\u5beb\u7a0b\u5f0f\uff0c\u8981\u8003\u616e\u7684\u7d55\u5c0d\u4e0d\u53ea\u4e0a\u9762\u9019\u4e9b\u57fa\u672c\u7684\u8cc7\u6599\u578b\u614b\u3002\u9664\u4e86 pointer \u7684\u5927\u5c0f\u8b8a\u6210 64-bit \u5916\uff0c\u8a31\u591a\u7cfb\u7d71\u5167\u5efa\u51fd\u5f0f\u6703\u7528\u5230\u7684 size_t \u53ca off_t \u7684\u5927\u5c0f\u4e5f\u8b8a\u6210 64-bit \u4e86&#8230;. \u5beb\u7a0b\u5f0f\u6642\u82e5\u6709\u7528\u5230\u9019\u4e9b\u8cc7\u6599\u578b\u614b\uff0c\u9700\u7279\u5225\u6ce8\u610f\uff0c\u5c24\u5176\u662f casting \u6642\uff0c\u5343\u842c\u4e0d\u8981\u7528 32-bit \u7684\u6574\u6578\u53bb\u88dd\u9019\u4e9b\u8cc7\u6599\uff0c\u514d\u5f97\u9020\u6210\u4e0d\u53ef\u9810\u671f\u7684\u7d50\u679c\uff01<\/p>\n<p>\u6700\u5f8c\u63d0\u4f9b\u4e00\u500b\u5c0f\u7a0b\u5f0f\u8b93\u4f60\u5f97\u77e5\u4f60\u7684\u7cfb\u7d71\u4e3b\u8981\u8cc7\u6599\u578b\u614b\u7684\u5927\u5c0f<\/p>\n<pre lang=\"c\" line=\"1\">#include <stdio.h>\n#include <sys types.h=\"\">\nint main()\n{\n        printf(\"sizeof(short)     = %d\\n\", sizeof(short));\n        printf(\"sizeof(int)       = %d\\n\", sizeof(int));\n        printf(\"sizeof(long)      = %d\\n\", sizeof(long));\n        printf(\"sizeof(long long) = %d\\n\\n\", sizeof(long long));\n\n        printf(\"sizeof(size_t)    = %d\\n\", sizeof(size_t));\n        printf(\"sizeof(off_t)     = %d\\n\", sizeof(off_t));\n        printf(\"sizeof(void *)    = %d\\n\", sizeof(void *));\n}\n<\/sys><\/stdio.h><\/pre>\n<p>\u53c3\u8003\u8cc7\u6599:<\/p>\n<ol>\n<li>Wikipedia: <a href=\"http:\/\/en.wikipedia.org\/wiki\/64-bit#64-bit_data_models\" target=\"_blank\">64-bit data models<\/a><\/li>\n<li><a href=\"http:\/\/www.unix.org\/version2\/whatsnew\/lp64_wp.html\" target=\"_blank\">64-Bit Programming Models: Why LP64?<\/a><\/li>\n<li><a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/bb496995.aspx\" target=\"_blank\">Introduction to Win32\/Win64<\/a><\/li>\n<li><a href=\"http:\/\/softwarecommunity.intel.com\/articles\/eng\/1660.htm\" target=\"_blank\">Porting 32-bit Applications to the Itanium\u00ae Architecture<\/a><\/li>\n<li><a href=\"http:\/\/cache-www.intel.com\/cd\/00\/00\/01\/79\/17969_codeclean_r02.pdf\" target=\"_blank\">Preparing Code for the IA-64 Architecture<\/a> (PDF)<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Size of long integer may be different between 64-bit sy [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9,10],"tags":[],"class_list":["post-85","post","type-post","status-publish","format-standard","hentry","category-os","category-language"],"views":75933,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pubdi-1n","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":84,"url":"https:\/\/dada.tw\/blog\/2008\/04\/18\/84\/","url_meta":{"origin":85,"position":0},"title":"Bypass the 2GB file size limit on 32-bit Linux","author":"dada","date":"2008-04-18","format":false,"excerpt":"Bypass the 2GB file size limit on 32-bit Linux (\u5728 \u2026","rel":"","context":"\u5728\u300c\u4f5c\u696d\u7cfb\u7d71\u300d\u4e2d","block_context":{"text":"\u4f5c\u696d\u7cfb\u7d71","link":"https:\/\/dada.tw\/blog\/category\/comp\/os\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":61,"url":"https:\/\/dada.tw\/blog\/2007\/11\/02\/61\/","url_meta":{"origin":85,"position":1},"title":"OpenBSD 4.2 &#8211; \u6709\u5b98\u65b9\u5b89\u88dd\u5149\u789f\u4e86","author":"dada","date":"2007-11-02","format":false,"excerpt":"OpenBSD 4.2 just released on Nov 1, 2007! \u5f9e\u9019\u7248\u958b\u59cb\uff0c\u5b98\u65b9\u2026","rel":"","context":"\u5728\u300c\u4f5c\u696d\u7cfb\u7d71\u300d\u4e2d","block_context":{"text":"\u4f5c\u696d\u7cfb\u7d71","link":"https:\/\/dada.tw\/blog\/category\/comp\/os\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9,"url":"https:\/\/dada.tw\/blog\/2005\/04\/21\/9\/","url_meta":{"origin":85,"position":2},"title":"\u7d42\u65bc\u628a NetBSD 2.0.2 \u88dd\u8d77\u4f86\u4e86!","author":"dada","date":"2005-04-21","format":false,"excerpt":"\u7d93\u904e\u5169\u5929\u7684\u52aa\u529b\uff0c\u7d42\u65bc\u9084\u662f\u628a NetBSD 2.0.2 \u88dd\u8d77\u4f86\u4e86! \u5176\u5be6\u672c\u4f86\u5148\u6e2c FreeBSD 5.\u2026","rel":"","context":"\u5728\u300c\u4f5c\u696d\u7cfb\u7d71\u300d\u4e2d","block_context":{"text":"\u4f5c\u696d\u7cfb\u7d71","link":"https:\/\/dada.tw\/blog\/category\/comp\/os\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":64,"url":"https:\/\/dada.tw\/blog\/2006\/10\/06\/64\/","url_meta":{"origin":85,"position":3},"title":"svndumpfilter with wildcards support ?","author":"dada","date":"2006-10-06","format":false,"excerpt":"Subversion \u7684 svnadmin obliterate \u529f\u80fd\u4e00\u76f4\u6c92\u6709\u5be6\u4f5c\u51fa\u4f86\uff0c\u9019\u5be6\u5728\u662f\u6709\u9ede\u2026","rel":"","context":"\u5728\u300c\u8edf\u9ad4\u300d\u4e2d","block_context":{"text":"\u8edf\u9ad4","link":"https:\/\/dada.tw\/blog\/category\/comp\/software\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":39,"url":"https:\/\/dada.tw\/blog\/2007\/05\/15\/39\/","url_meta":{"origin":85,"position":4},"title":"OpenBSD 4.1 &#8211; Unofficial ISO Image","author":"dada","date":"2007-05-15","format":false,"excerpt":"OpenBSD 4.1 released! \u95dc\u65bc OpenBSD 4.1 \u7684\u76f8\u95dc\u8cc7\u8a0a\u8acb\u53c3\u8003\uff1a htt\u2026","rel":"","context":"\u5728\u300c\u4f5c\u696d\u7cfb\u7d71\u300d\u4e2d","block_context":{"text":"\u4f5c\u696d\u7cfb\u7d71","link":"https:\/\/dada.tw\/blog\/category\/comp\/os\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":44,"url":"https:\/\/dada.tw\/blog\/2005\/11\/03\/44\/","url_meta":{"origin":85,"position":5},"title":"FreeBSD 6.0-RELEASE","author":"dada","date":"2005-11-03","format":false,"excerpt":"\u6700\u8fd1 BSD \u5bb6\u65cf\u771f\u5fd9\uff0c\u5148\u662f OpenBSD 3.8 \u767c\u4f48\uff0c\u7136\u5f8c\u662f NetBSD 2.1\uff0c\u63a5\u8457 Fr\u2026","rel":"","context":"\u5728\u300c\u4f5c\u696d\u7cfb\u7d71\u300d\u4e2d","block_context":{"text":"\u4f5c\u696d\u7cfb\u7d71","link":"https:\/\/dada.tw\/blog\/category\/comp\/os\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/posts\/85","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/comments?post=85"}],"version-history":[{"count":0,"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/posts\/85\/revisions"}],"wp:attachment":[{"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/media?parent=85"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/categories?post=85"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/tags?post=85"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}