{"id":229,"date":"2008-11-17T15:34:53","date_gmt":"2008-11-17T07:34:53","guid":{"rendered":"http:\/\/www.cgdev.net\/blog\/?p=229"},"modified":"2013-07-02T18:57:27","modified_gmt":"2013-07-02T10:57:27","slug":"%e4%bd%bf%e7%94%a8unaligned","status":"publish","type":"post","link":"https:\/\/www.cgdev.net\/blog\/229.html","title":{"rendered":"\u4f7f\u7528UNALIGNED"},"content":{"rendered":"<p>\u4eca\u5929\u518d\u6b21\u9047\u5230\u5b57\u8282\u5bf9\u9f50\u95ee\u9898\uff0c\u6ce8\u610f\u5728crtdefs.h\u6587\u4ef6\u4e2d\u5b9a\u4e49\u4e3a<br \/>\n#if !defined(UNALIGNED)<br \/>\n#if defined(_M_IA64) || defined(_M_AMD64)<br \/>\n#define UNALIGNED __unaligned<br \/>\n#else<br \/>\n#define UNALIGNED<br \/>\n#endif<br \/>\n#endif<\/p>\n<p>\u53ef\u89c1\u572832\u4f4d\u7cfb\u7edf\u4e2d\u7528UNALIGNED\u548c\u6ca1\u7528\u662f\u4e00\u6837\u7684\uff0c\u4f46\u5728ia64\u6216\u8005amd64\u5e73\u53f0\u4e0b\uff0c\u5c31\u4e0d\u540c\u4e86\uff0c__unaligned<br \/>\n\u5173\u952e\u5b57\u4f1a\u6307\u793a\u7f16\u8bd1\u5668\u4e00\u6b21\u8bfb\u4e00\u4e2a\u5b57\u8282\uff0c\u518d\u770b\u770bMSDN\u7ed9\u7684\u4f8b\u5b50:<br \/>\n\/\/ unaligned_keyword.cpp<br \/>\n\/\/ compile with: \/c<br \/>\n\/\/ processor: x64 IPF<br \/>\n#include <stdio.h><br \/>\nint main()<br \/>\n{<br \/>\n char buf[100];<br \/>\n int __unaligned *p1 = (int*)(&#038;buf[37]);<br \/>\n int *p2 = (int *)p1;<br \/>\n *p1 = 0; \/\/ ok<br \/>\n __try<br \/>\n {<br \/>\n *p2 = 0; \/\/ throws an exception<br \/>\n }<br \/>\n __except(1)<br \/>\n {<br \/>\n puts(&#8220;exception&#8221;);<br \/>\n }<br \/>\n} <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u518d\u6b21\u9047\u5230\u5b57\u8282\u5bf9\u9f50\u95ee\u9898\uff0c\u6ce8\u610f\u5728crtdefs.h\u6587\u4ef6\u4e2d\u5b9a\u4e49\u4e3a #if !defined(UNALIGNED) #if defined(_M_IA64) || defined(_M_AMD64) #define UNALIGNED __unaligned #else #define UNALIGNED #endif #endif \u53ef\u89c1\u572832\u4f4d\u7cfb\u7edf\u4e2d\u7528UNALIGNED\u548c\u6ca1\u7528\u662f\u4e00\u6837\u7684\uff0c\u4f46\u5728ia64\u6216\u8005amd64\u5e73\u53f0\u4e0b\uff0c\u5c31\u4e0d\u540c\u4e86\uff0c__unaligned \u5173\u952e\u5b57\u4f1a\u6307\u793a\u7f16\u8bd1\u5668\u4e00\u6b21\u8bfb\u4e00\u4e2a\u5b57\u8282\uff0c\u518d\u770b\u770bMSDN\u7ed9\u7684\u4f8b\u5b50: \/\/ unaligned_keyword.cpp \/\/ compile with: \/c \/\/ processor: x64 IPF #include int main() { char buf[100]; int __unaligned *p1 = (int*)(&#038;buf[37]); int *p2 = (int *)p1; *p1 = 0; \/\/ ok __try { *p2 = 0; \/\/ throws [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-cpp"],"_links":{"self":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/comments?post=229"}],"version-history":[{"count":0,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cgdev.net\/blog\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}