{"id":217417,"date":"2020-12-03T23:25:22","date_gmt":"2020-12-03T15:25:22","guid":{"rendered":"http:\/\/4563.org\/?p=217417"},"modified":"2020-12-03T23:25:22","modified_gmt":"2020-12-03T15:25:22","slug":"c-%e8%af%ad%e8%a8%80%e6%8c%87%e9%92%88%e4%bc%a0%e9%80%92%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=217417","title":{"rendered":"C \u8bed\u8a00\u6307\u9488\u4f20\u9012\u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  C \u8bed\u8a00\u6307\u9488\u4f20\u9012\u7684\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u8fd9\u4e2a\u662f C++\u548c Python \u6df7\u5408\u7f16\u7a0b\u7684\u95ee\u9898\uff0c\u6240\u4ee5\u4e25\u683c\u6765\u8bf4\u4f3c\u4e4e\u6807\u9898\u4e0d\u51c6\u786e\uff1f<\/p>\n<p>\u5982\u540c\u524d\u51e0\u5929\u53d1\u7684\u5e16\u5b50\u91cc\u6240\u8bf4\uff0c\u6211\u4ecd\u5728\u8fdb\u884c cython \u7f16\u7a0b\u6d4b\u8bd5\uff0c\u4e3a\u4e86\u5728 C \u7684\u57fa\u672c\u8bed\u6cd5\u4e0b\u5728 cython \u4e2d\u590d\u73b0\u4e00\u4e9b python \u5e38\u89c1\u64cd\u4f5c\u3002<\/p>\n<p>\u6bd4\u5982\u4ee5\u4e0b\u8fd9\u4e2a\u573a\u666f\uff1a\u6211\u5728\u547d\u540d\u7a7a\u95f4 main \u4e2d\u6709\u4e00\u4e2a\u6570\u7ec4\uff08\u6216\u8005\u5411\u91cf\uff09 a\uff0c\u6211\u5e0c\u671b\u5c06 a \u4e22\u5165\u67d0\u4e2a\u51fd\u6570\u5904\u7406\u8fc7\u540e\uff0c\u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u503c\uff0c\u4f46 a \u88ab\u4fee\u6539\uff0c\u8fd9\u79cd\u663e\u7136\u662f\u4f20\u5165\u4e00\u4e2a\u6307\u9488\uff0c\u5728 python \u4e2d\u7c7b\u4f3c\u4e8e\u4f20\u5165 list \u6216\u8005 dict \u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u6d4b\u8bd5\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code># distutils: language=c++ import cython from libcpp.vector cimport vector  cdef operation(vector[cython.float] *p):     p.push_back(99)  def main():     # \u9996\u5148\u51c6\u5907\u4e00\u4e2a\u5411\u91cf      cdef vector[cython.float] lst     cdef int i      for i in range(5):         lst.push_back(i)     # \u4e22\u5165\u51fd\u6570     operation(&amp;lst)     # \u67e5\u770b\u7ed3\u679c     print(lst) <\/code><\/pre>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u662f\u80fd\u591f\u8fd0\u884c\u7684\uff0c\u8fd4\u56de\u7ed3\u679c[0,1,2,3,4,99]\uff0c\u7b26\u5408\u9884\u671f\u3002 \u4f46\u662f\u4ecd\u6709\u4e00\u4e9b\u7591\u60d1\uff0c\u65e2\u7136\u8f93\u5165\u51fd\u6570\u7684&amp;lst \u662f\u6307\u9488\u7684\u8bdd\uff0c\u90a3 operation \u51fd\u6570\u4e2d\u8c03\u7528\u8fd9\u4e2a\u6307\u9488\u503c\u7684\u65f6\u5019\uff0c\u4e0d\u662f\u5e94\u8be5\u524d\u9762\u52a0\u661f\u53f7\u624d\u80fd\u53d6\u5230\u5b9e\u9645\u5bf9\u8c61\u4e48\uff0c\u6240\u4ee5\u4e0d\u662f\u5e94\u8be5\u662f<code>*p.push_back(99)<\/code>\u624d\u80fd\u751f\u6548\u624d\u5bf9\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u9700\u8981\u52a0\u4e5f\u80fd\u8fd0\u884c\u5462\u3002<\/p>\n<p>\u5176\u6b21\u5c06\u4e0a\u6587\u4e2d operation \u51fd\u6570\u5185\u5bb9\u4fee\u6539\u4e3a p[0] += 1\uff0c\u4e0a\u6b21\u5c1d\u8bd5\u65b0\u589e\u9879\u76ee\uff0c\u8fd9\u6b21\u5c1d\u8bd5\u4fee\u6539\u9879\u76ee\uff0c\u671f\u671b\u8fd4\u56de\u503c\u4e3a[1,1,2,3,4]\uff0c\u7136\u800c\u7f16\u8bd1\u62a5\u9519<\/p>\n<pre><code>test.cpp(1191): error C2676: \u4e8c\u8fdb\u5236\u201c+=\u201d:\u201cstd::vector&lt;float,std::allocator&lt;_Ty&gt;&gt;\u201d\u4e0d\u5b9a\u4e49\u8be5\u8fd0\u7b97\u7b26\u6216\u5230 \u9884\u5b9a\u4e49\u8fd0\u7b97\u7b26\u53ef\u63a5\u6536\u7684\u7c7b\u578b\u7684\u8f6c\u6362         with         [             _Ty=float         ] <\/code><\/pre>\n<p>\u4e3a\u4ec0\u4e48\u4f1a\u62a5\u9519\uff0c\u4e24\u8005\u6709\u4ec0\u4e48\u533a\u522b\u5462\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4421742\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Jabin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             operation *p \u662f\u6307\u9488\uff0c\u4f20\u5165\u53c2\u6570&amp;lst \u662f\u5730\u5740\uff0c*p \u6307\u5411 lst \u5730\u5740\uff0cp[0] \u662f lst[0]\u7684\u5730\u5740+1 \u91cd\u65b0\u8d4b\u503c\uff0c\u6307\u5411\u54ea\u91cc\u5c31\u4e0d\u77e5\u9053\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4421743\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u5f97\u770b cython \u8f6c\u6362\u6210 c \u8c03\u7528 gcc \u7f16\u8bd1\u65f6\u7684\u4ee3\u7801\u662f\u5565\u6837\u7684\uff0c\u4e5f\u8bb8 cython \u7684\u8bed\u6cd5\u5c31\u662f\u8fd9\u6837\u7684\u5462                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4421744\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Jabin p0 \u662f\u53ef\u4ee5\u53d6\u503c\u7684\u6bd4\u5982 print p0 \u8fd9\u79cd\u662f\u53ef\u4ee5\u6267\u884c\u7684\uff0c\u4f46\u662f\u4e0d\u80fd\u52a0\u4e00\uff0c\u5c31\u5f88\u602a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>C \u8bed\u8a00\u6307\u9488\u4f20\u9012\u7684\u95ee\u9898 \u8cc7\u6df1\u5927\u4f6c &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\/217417"}],"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=217417"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/217417\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217417"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}