{"id":201739,"date":"2020-11-25T06:26:18","date_gmt":"2020-11-24T22:26:18","guid":{"rendered":"http:\/\/4563.org\/?p=201739"},"modified":"2020-11-25T06:26:18","modified_gmt":"2020-11-24T22:26:18","slug":"golang-%e4%b8%ad%e7%9a%84%e5%88%87%e7%89%87%e5%9c%b0%e5%9d%80","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=201739","title":{"rendered":"golang \u4e2d\u7684\u5207\u7247\u5730\u5740"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  golang \u4e2d\u7684\u5207\u7247\u5730\u5740               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Chaox <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code> func main() {     months := []string{1: \"January\"}     fmt.Printf(\"%p,n\",&amp;months)                \/\/0xc0000ae040,     fmt.Printf(\"%p,n\",months)                \/\/0xc0000ae060,     fmt.Printf(\"%p,n\",&amp;months[0])           \/\/0xc0000ae060, }  <\/code><\/pre>\n<p>\u6211\u77e5\u9053\u7b2c\u4e8c\u4e2a\u548c\u7b2c\u4e09\u4e2a\u6253\u5370\u51fd\u6570\u6307\u5411\u7684\u662f\u5e95\u5c42\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u5730\u5740\u3002 \u4f46\u662f\u6211\u60f3\u95ee\u7684\u662f\u7b2c\u4e00\u4e2a\u6253\u5370\u51fd\u6570\u4e2d\u6253\u5370\u7684\u5730\u5740\u6307\u5411\u7684\u662f\u4ec0\u4e48\uff1f \u5bf9\u5207\u7247\u8fd9\u4e2a\u5f15\u7528\u7c7b\u578b\uff08\u672c\u8eab\u4f20\u9012\u7684\u5c31\u662f\u5730\u5740\uff09\u53d6\u5730\u5740\u4f1a\u53d6\u5230\u4ec0\u4e48\u5462\uff1f<\/p>\n<p>\uff08\u6211\u5728 stackoverflow \u4e0a\u770b\u5230\u56de\u7b54\u662f\u6307\u5411 slice \u7684 header \u3002\u6211\u7684\u7591\u60d1\u662f\u8fd9\u4e2a header \u5982\u679c\u8868\u793a\u7684\u662f slice \u7ed3\u6784\u4f53\uff0c\u4f46\u662f slice \u7ed3\u6784\u4f53\u7684\u7b2c\u4e00\u4e2a\u6210\u5458\u53d8\u91cf\u5c31\u662f\u6570\u7ec4\u7684\u6307\u9488\uff0c\u90a3\u4e48\u7ed3\u6784\u4f53\u7684\u5730\u5740\u4e0d\u5c31\u662f\u7b2c\u4e00\u4e2a\u6210\u5458\u53d8\u91cf\u7684\u5730\u5740\u5417\uff0c\u4e0d\u5c31\u662f\u5e95\u5c42\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u5417\uff1f\uff09<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4312129\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : johnkiller <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             months \u662f\u4e00\u4e2a\u6307\u9488\u53d8\u91cf\uff0c\u5b58\u4e00\u4e2a\u5730\u5740\uff0c\u6307\u5411\u8fd9\u4e2a\u5207\u7247\u3002<\/p>\n<p>\u8fd9\u4e2a\u6307\u9488\u53d8\u91cf\u540c\u6837\u9700\u8981\u4e00\u4e2a\u5185\u5b58\u5730\u5740\u6765\u5b58\u50a8\u3002<\/p>\n<p>int *p;<\/p>\n<p>int a = 5;<\/p>\n<p>p = &amp;a;<\/p>\n<p>p \u5b58\u4e86 a \u7684\u5730\u5740\uff0c\u4f46 p \u672c\u8eab\u4e5f\u9700\u8981\u4e00\u4e2a\u5185\u5b58\u5730\u5740\u6765\u5b58\u50a8\u3002<\/p>\n<p>\u628a p \u7406\u89e3\u6210\u4e00\u4e2a cpu \u5b57\u957f\u5927\u5c0f\u7684\u6574\u5f62\u53d8\u91cf\uff0c\u4ed6\u5b58\u4e86\u4e00\u4e2a\u6574\u5f62\u5730\u5740\u3002\u6240\u4ee5\u5b83\u4e5f\u9700\u8981\u4e00\u4e2a\u5185\u5b58\u5730\u5740\u3002<\/p>\n<p>\u4e2a\u4eba\u7406\u89e3\uff0c\u5982\u679c\u6709\u9519\u611f\u8c22\u6307\u6b63\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4312130\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lujjjh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             fmt.Printf(&#8220;0x%xn&#8221;, (*reflect.SliceHeader)(unsafe.Pointer(&amp;months)).Data)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4312131\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hellos <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7b2c\u4e00\u4e2a\u662f\u6307\u9488\u81ea\u5df1\u7684\u5730\u5740                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4312132\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : icexin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             func main() {<br \/> months := []string{1: &#8220;January&#8221;}<br \/> fmt.Printf(&#8220;%p,n&#8221;, &amp;months)<br \/> fmt.Printf(&#8220;%p,n&#8221;, months)<br \/> fmt.Printf(&#8220;%p,n&#8221;, &amp;months[0])<\/p>\n<p> header := (*reflect.SliceHeader)(unsafe.Pointer(&amp;months))<br \/> fmt.Printf(&#8220;%p,n&#8221;, header)<br \/> fmt.Printf(&#8220;0x%x,n&#8221;, header.Data)<br \/> fmt.Printf(&#8220;0x%x,n&#8221;, header.Data+0)<br \/>}<\/p>\n<p>\u628a\u4f60\u7684\u4ee3\u7801\u7ffb\u8bd1\u4e86\u4e00\u4e0b\uff0c\u524d\u9762\u7684\u51e0\u4e2a\u6253\u5370\u8bed\u53e5\u7b49\u4ef7\u4e8e\u540e\u9762\u7684\u4e09\u884c                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4312133\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : whoami9894 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7b2c\u4e00\u884c\u6253\u5370 months \u53d8\u91cf\u5730\u5740 (SliceHeader)<br \/>\u7b2c\u4e8c\u884c\u4ece months \u53d8\u91cf\u5730\u5740\u5904\u53d6\u4e00\u4e2a\u6307\u9488\u53d8\u91cf\u7684\u957f\u5ea6\u5f53\u505a\u6307\u9488\u6253\u5370 (SliceHeader \u5f00\u5934\u4e5f\u6b63\u597d\u662f uintptr)<br \/>\u7b2c\u4e09\u884c\u6253\u5370 slice \u6307\u5411\u7684\u5e95\u5c42\u6570\u7ec4\u7b2c\u4e00\u4e2a\u5143\u7d20\u5730\u5740                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4312134\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Chaox <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @johnkiller \u8c22\u8c22\uff0c\u7406\u89e3\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4312135\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Chaox <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @icexin \u8c22\u8c22\uff0c\u660e\u767d\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>golang \u4e2d\u7684\u5207\u7247\u5730\u5740 \u8cc7\u6df1\u5927&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/201739"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=201739"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/201739\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=201739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=201739"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=201739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}