{"id":2141,"date":"2023-03-27T11:34:39","date_gmt":"2023-03-27T03:34:39","guid":{"rendered":"https:\/\/courtship.top\/?p=2141"},"modified":"2023-03-27T11:34:39","modified_gmt":"2023-03-27T03:34:39","slug":"%e6%8c%87%e9%92%88%e5%87%bd%e6%95%b0-%e5%87%bd%e6%95%b0%e6%8c%87%e9%92%88","status":"publish","type":"post","link":"https:\/\/courtship.top\/index.php\/2023\/03\/27\/%e6%8c%87%e9%92%88%e5%87%bd%e6%95%b0-%e5%87%bd%e6%95%b0%e6%8c%87%e9%92%88\/","title":{"rendered":"\u6307\u9488\u51fd\u6570 \u51fd\u6570\u6307\u9488"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>CSDN:<a class=\"\" rel=\"noreferrer noopener\" href=\"https:\/\/blog.csdn.net\/xc_123\" target=\"_blank\" rel=\"nofollow\" >\u60df\u8096\u8096\u8096<\/a><\/p>\n<cite>http:\/\/t.csdn.cn\/gAIBV<\/cite><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u6307\u9488\u51fd\u6570<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u672c\u8d28\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u4e0d\u8fc7\u5b83\u7684\u8fd4\u56de\u503c\u662f\u4e00\u4e2a\u6307\u9488\u3002<\/h3>\n\n\n\n<p>\u5176\u58f0\u660e\u7684\u5f62\u5f0f\uff1a<strong>\u7c7b\u578b\u540d *\u51fd\u6570\u540d(\u51fd\u6570\u53c2\u6570\u5217\u8868)<\/strong>;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int * pfun(int, int);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u8fd4\u56de\u7c7b\u578b\u53ef\u4ee5\u662f\u4efb\u4f55\u57fa\u672c\u7c7b\u578b\u548c\u590d\u5408\u7c7b\u578b\u3002<\/h3>\n\n\n\n<p>\u8fd4\u56de\u6307\u9488\u7684\u51fd\u6570\u7684\u7528\u9014\u5341\u5206\u5e7f\u6cdb\u3002<strong>\u4e8b\u5b9e\u4e0a\uff0c\u6bcf\u4e00\u4e2a\u51fd\u6570\uff0c\u5373\u4f7f\u5b83\u4e0d\u5e26\u6709\u8fd4\u56de\u67d0\u79cd\u7c7b\u578b\u7684\u6307\u9488\uff0c\u5b83\u672c\u8eab\u90fd\u6709\u4e00\u4e2a\u5165\u53e3\u5730\u5740\uff0c\u8be5\u5730\u5740\u76f8\u5f53\u4e8e\u4e00\u4e2a\u6307\u9488\u3002<\/strong>\u6bd4\u5982\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u6574\u578b\u503c\uff0c\u5b9e\u9645\u4e0a\u4e5f\u76f8\u5f53\u4e8e\u8fd4\u56de\u4e00\u4e2a\u6307\u9488\u53d8\u91cf\u7684\u503c\uff0c\u4e0d\u8fc7\u8fd9\u65f6\u7684\u53d8\u91cf\u662f\u51fd\u6570\u672c\u8eab\u800c\u5df2\uff0c\u800c\u6574\u4e2a\u51fd\u6570\u76f8\u5f53\u4e8e\u4e00\u4e2a\u201c\u53d8\u91cf\u201d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">void\u578b\u6307\u9488<\/h3>\n\n\n\n<p><strong>void\u6307\u9488\u662f\u4e00\u79cd\u4e0d\u660e\u786e\u7c7b\u578b\u7684\u6307\u9488\uff0c\u4efb\u4f55\u6307\u9488\u90fd\u53ef\u8f6c\u6362\u4e3avoid\u6307\u9488\u3002<\/strong>    <\/p>\n\n\n\n<p>\u6307\u9488\u6709\u4e24\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u4fe1\u606f\uff1a \u6307\u9488\u7684\u503c\uff08\u6307\u9488\u76ee\u6807\u5bf9\u8c61\u7684\u5185\u5b58\u9996\u5730\u5740\uff09 \u6307\u9488\u6307\u5411\u5bf9\u8c61\u7684\u7c7b\u578b     <\/p>\n\n\n\n<p><strong>\u6ce8\u610f\u70b9<\/strong>\uff1avoid\u6307\u9488\u53ea\u4fdd\u5b58\u4e86 \u6307\u9488\u7684\u503c \u5e76\u6ca1\u6709\u8bb0\u5f55 \u6307\u9488\u6307\u5411\u5bf9\u8c61\u7684\u7c7b\u578b\u3002\u56e0\u6b64\u5728\u7528\u5230\u5bf9void\u6307\u9488\u89e3\u5f15\u65f6\uff0c\u9700\u8981\u5148\u628avoid\u6307\u9488\u8f6c\u6362\u6210\u539f\u672c\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int n = 500; \/\/\u5b9a\u4e49\u4e00\u4e2aint\u53d8\u91cf\nint * p = &amp;n; \/\/\u5b9a\u4e49int\u7c7b\u578b\u6307\u9488\nvoid * pv = p; \/\/\u5b9a\u4e49void\u6307\u9488\uff0c\u53ea\u4fdd\u5b58\u4e86p\u7684\u503c\uff08\u5373n\u7684\u5185\u5b58\u9996\u5730\u5740\uff09\n\n\/\/\u9519\u8bef\u7684\u5199\u6cd5\nprintf(\"%d\\n\", *pv); \/\/\u8fd9\u91cc\u4f1a\u62a5\u9519\uff0c\u56e0pv\u6307\u9488\u6ca1\u6709\u660e\u786e\u6570\u636e\u7c7b\u578b\uff0c\u56e0\u6b64\u4e5f\u4e0d\u77e5\u9053\u9700\u8981\u53d6\u591a\u5c11\u5b57\u8282\u7684\u6570\u636e\n\n\/\/\u6b63\u786e\u5199\u6cd5\nprintf(\"%d\\n\", *( (int*)pv ) ); \/\/\u5148\u628apv\u6307\u9488\u8f6c\u4e3aint\u7c7b\u578b\u6307\u9488\uff0c\u518d\u5bf9\u5176\u89e3\u5f15<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u51fd\u6570\u6307\u9488<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u51fd\u6570\u6307\u9488\u662f\u6307\u5411\u51fd\u6570\u7684\u6307\u9488\u53d8\u91cf\u3002 <\/h3>\n\n\n\n<p>\u56e0\u6b64\u201c\u51fd\u6570\u6307\u9488\u201d\u672c\u8eab\u9996\u5148\u5e94\u662f\u6307\u9488\u53d8\u91cf\uff0c<strong>\u53ea\u4e0d\u8fc7\u8be5\u6307\u9488\u53d8\u91cf\u6307\u5411\u51fd\u6570<\/strong>\u3002<\/p>\n\n\n\n<p>C\u5728\u7f16\u8bd1\u65f6\uff0c\u6bcf\u4e00\u4e2a\u51fd\u6570\u90fd\u6709\u4e00\u4e2a\u5165\u53e3\u5730\u5740\uff0c\u8be5\u5165\u53e3\u5730\u5740\u5c31\u662f\u51fd\u6570\u6307\u9488\u6240\u6307\u5411\u7684\u5730\u5740\u3002\u6709\u4e86\u6307\u5411\u51fd\u6570\u7684\u6307\u9488\u53d8\u91cf\u540e\uff0c\u53ef\u7528\u8be5\u6307\u9488\u53d8\u91cf\u8c03\u7528\u51fd\u6570\uff0c\u5c31\u5982\u540c\u7528\u6307\u9488\u53d8\u91cf\u53ef\u5f15\u7528\u5176\u4ed6\u7c7b\u578b\u53d8\u91cf\u4e00\u6837\uff0c\u5728\u8fd9\u4e9b\u6982\u5ff5\u4e0a\u662f\u5927\u4f53\u4e00\u81f4\u7684\u3002\u51fd\u6570\u6307\u9488\u6709\u4e24\u4e2a\u7528\u9014\uff1a\u8c03\u7528\u51fd\u6570\u548c\u505a\u51fd\u6570\u7684\u53c2\u6570\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u51fd\u6570\u6307\u9488\u7684\u58f0\u660e\u65b9\u6cd5\u4e3a\uff1a<\/h3>\n\n\n\n<p><strong>\u8fd4\u56de\u503c\u7c7b\u578b ( * \u6307\u9488\u53d8\u91cf\u540d) ([\u5f62\u53c2\u5217\u8868]);<\/strong><\/p>\n\n\n\n<p>\u201c\u8fd4\u56de\u503c\u7c7b\u578b\u201d\u8bf4\u660e\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\uff0c\u201c(\u6307\u9488\u53d8\u91cf\u540d )\u201d\u4e2d\u7684\u62ec\u53f7\u4e0d\u80fd\u7701\uff0c\u62ec\u53f7\u6539\u53d8\u4e86\u8fd0\u7b97\u7b26\u7684\u4f18\u5148\u7ea7\u3002\u82e5\u7701\u7565\u6574\u4f53\u5219\u6210\u4e3a\u4e00\u4e2a\u51fd\u6570\u8bf4\u660e\uff0c\u8bf4\u660e\u4e86\u4e00\u4e2a\u8fd4\u56de\u7684\u6570\u636e\u7c7b\u578b\u662f\u6307\u9488\u7684\u51fd\u6570\uff0c\u540e\u9762\u7684\u201c\u5f62\u53c2\u5217\u8868\u201d\u8868\u793a\u6307\u9488\u53d8\u91cf\u6307\u5411\u7684\u51fd\u6570\u6240\u5e26\u7684\u53c2\u6570\u5217\u8868\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>int func(int x); \/* \u58f0\u660e\u4e00\u4e2a\u51fd\u6570 *\/<\/li>\n\n\n\n<li>int (<em>f) (int x); \/<\/em> \u58f0\u660e\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff0c\u662f\u4e00\u4e2a\u6307\u5411\u8fd4\u56de\u503c\u4e3aint\u7684\u51fd\u6570\u7684\u6307\u9488 *\/<\/li>\n\n\n\n<li>f=func; \/* \u5c06func\u51fd\u6570\u7684\u9996\u5730\u5740\u8d4b\u7ed9\u6307\u9488f *\/<\/li>\n<\/ul>\n\n\n\n<p>\u6216\u8005\u4f7f\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u5c06\u51fd\u6570\u5730\u5740\u8d4b\u7ed9\u51fd\u6570\u6307\u9488\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>f = &amp;func;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\nvoid func(int x) { std::cout &lt;&lt; \"simple func \" &lt;&lt; x &lt;&lt; std::endl; }\nvoid funcx(int a, int b) { std::cout &lt;&lt; a &lt;&lt; \" \" &lt;&lt; b &lt;&lt; std::endl; }\n\nvoid (*p)(int);\n\nvoid func2(void (*p)(int), void(*x)(int, int)) {\n    (*p)(2);\n    (*x)(3, 3);\n}\n\nstatic float score&#91;]&#91;4] = { {60,70,80,90},{56,89,34,45},{34,23,56,45}};\n\nint main()\n{\n    p = func;\n    (*p)(6);\n\n    func2(func, funcx);\n\n    std::cout &lt;&lt; *(*(score + 1)) &lt;&lt; std::endl;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Typedef\u5173\u952e\u5b57\u4e0e\u610f\u4e49<\/h2>\n\n\n\n<p>int (*PF)(int *, int); PF\u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488\u53d8\u91cf\uff0c\u7528\u4e8e\u6307\u5411\u8fd4\u56de\u503c\u4e3aint\uff0c\u4e00\u4e2aint\u7c7b\u578b\u53c2\u6570\u7684\u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u5f53\u4f7f\u7528typedef\u58f0\u660e\u540e\uff0c\u5219PF\u5c31\u6210\u4e3a\u4e86\u4e00\u4e2a\u51fd\u6570\u6307\u9488\u7c7b\u578b\uff0c\u5373 typedef int (*PF)(int *, int); \u8fd9\u6837\u5c31\u5b9a\u4e49\u4e86\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>\u518d\u7528PF\u4f5c\u4e3a\u8fd4\u56de\u503c\u6765\u58f0\u660e\u51fd\u6570\uff1aPF func(int); \/\/ func\uff08int\uff09\u5c31\u662f\u4e00\u4e2a\u8fd4\u56de\u503c\u4e3a\u51fd\u6570\u6307\u9488\uff0c\u4e00\u4e2aint\u7c7b\u578b\u53c2\u6570\u7684\u51fd\u6570<\/p>\n\n\n\n<p>\u518d\u7528PF\u6765\u58f0\u660e\uff1aPF phead; \/\/phead\u5c31\u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>typedef int a&#91;10]; \/\/ a \u7c7b\u578b\u662f int&#91;10];\uff08\u5b58\u653eint\u578b\u6570\u636e\u7684\u6570\u7ec4\uff09\na arr; \/\/ \u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\uff1aint arr&#91;3];\n\ntypedef void (*p)(void); \/\/p \u7c7b\u578b\u662fvoid ( * )void\np A; \/\/\u662f\u6307void(*A)(void);<\/code><\/pre>\n\n\n\n<p>\u8bed\u6cd5\u4e0atypedef\u5c5e\u4e8e\u5b58\u50a8\u7c7b\u58f0\u660e\u8bf4\u660e\u7b26\u3002<br \/>a[10]\u4e0d\u662fint\u7684\u522b\u540d\uff0c(*p)(void)\u4e0d\u662fvoid\u7684\u522b\u540d\u3002<br \/>\u4e0a\u9762\u7684\u8bed\u53e5\u628aa\u58f0\u660e\u4e3a\u5177\u670910\u4e2aint\u5143\u7d20\u7684\u6570\u7ec4\u7684\u7c7b\u578b\u522b\u540d\uff0cp\u662f\u4e00\u79cd\u51fd\u6570\u6307\u9488\u7684\u7c7b\u578b\u522b\u540d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u51fd\u6570\u6307\u9488\u5bf9\u8c61\u8d4b\u503c\u7528\u6cd5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>typedef void (*IapFun)(void);  \/\/\u5b9a\u4e49\u51fd\u6570\u6307\u9488\nvoid func(void);               \/\/\u5b9a\u4e49\u51fd\u6570\nIapFun fun  = func;            \/\/\u4e3a\u51fd\u6570\u6307\u9488\u5bf9\u8c61\u8d4b\u503c\nfun();                         \/\/\u8fd9\u91cc\u7684fun()\u5176\u5b9e\u5c31\u76f8\u5f53\u4e8e\u8df3\u8f6c\u5230\u4e86func()\u91cc<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>typedef void (* IapFun)(void);          \/\/\u5b9a\u4e49\u51fd\u6570\u6307\u9488\nIapFun jump2app;                         \/\/\u5b9a\u4e49\u51fd\u6570\u6307\u9488\u5bf9\u8c61\njump2app=(IapFun) * (vu32*)(appxaddr+4); \/\/\u4e3a\u51fd\u6570\u6307\u9488\u5bf9\u8c61\u8d4b\u503c appxaddr\u4e3a\u51fd\u6570\u6307\u9488\u5730\u5740,\u4f8b\u59820x08000000\njump2app();                              \/\/\u8c03\u7528\u51fd\u6570<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>CSDN:\u60df\u8096\u8096\u8096 http:\/\/t.csdn.cn\/gAIBV \u6307\u9488\u51fd\u6570 \u672c\u8d28\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u4e0d\u8fc7\u5b83\u7684\u8fd4\u56de\u503c\u662f\u4e00\u4e2a\u6307\u9488\u3002 \u5176\u58f0\u660e\u7684\u5f62 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[22],"tags":[],"class_list":["post-2141","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/2141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/comments?post=2141"}],"version-history":[{"count":0,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/2141\/revisions"}],"wp:attachment":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/media?parent=2141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/categories?post=2141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/tags?post=2141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}