{"id":177057,"date":"2020-04-23T10:46:12","date_gmt":"2020-04-23T02:46:12","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=177057"},"modified":"2020-04-18T10:47:18","modified_gmt":"2020-04-18T02:47:18","slug":"c-language-callback","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/c-language-callback.html","title":{"rendered":"C \u8bed\u8a00\u56de\u8c03\u51fd\u6570\u8be6\u89e3"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u56de\u8c03\u51fd\u6570\u5c31\u662f\u4e00\u4e2a\u901a\u8fc7\u51fd\u6570\u6307\u9488\u8c03\u7528\u7684\u51fd\u6570\u3002\u5982\u679c\u4f60\u628a\u51fd\u6570\u7684\u6307\u9488\uff08\u5730\u5740\uff09\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u53e6\u4e00\u4e2a\u51fd\u6570\uff0c\u5f53\u8fd9\u4e2a\u6307\u9488\u88ab\u7528\u6765\u8c03\u7528\u5176\u6240\u6307\u5411\u7684\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u5c31\u8bf4\u8fd9\u662f\u56de\u8c03\u51fd\u6570\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n 1. \u4ec0\u4e48\u662f\u56de\u8c03\u51fd\u6570\uff1f<\/strong><\/div>\n \u56de\u8c03\u51fd\u6570\uff0c\u5149\u542c\u540d\u5b57\u5c31\u6bd4\u666e\u901a\u51fd\u6570\u8981\u9ad8\u5927\u4e0a\u4e00\u4e9b\uff0c\u90a3\u5230\u5e95\u4ec0\u4e48\u662f\u56de\u8c03\u51fd\u6570\u5462\uff1f\u6055\u6211\u8bfb\u5f97\u4e66\u5c11\uff0c\u6ca1\u6709\u5728\u90a3\u672c\u4e66\u4e0a\u770b\u5230\u5173\u4e8e\u56de\u8c03\u51fd\u6570\u7684\u5b9a\u4e49\u3002\u6211\u5728\u767e\u5ea6\u4e0a\u641c\u4e86\u4e00\u4e0b\uff0c\u53d1\u73b0\u4f17\u8bf4\u7eb7\u7ead\uff0c\u6709\u5f88\u5927\u4e00\u90e8\u5206\u90fd\u662f\u4f7f\u7528\u7c7b\u4f3c\u8fd9\u4e48\u4e00\u4e2a\u573a\u666f\u6765\u8bf4\u660e\uff1aA\u541b\u53bbB\u541b\u5e97\u91cc\u4e70\u4e1c\u897f\uff0c\u6070\u597d\u7f3a\u8d27\uff0cA\u541b\u7559\u4e0b\u53f7\u7801\u7ed9B\u541b\uff0c\u6709\u8d27\u65f6\u901a\u77e5A\u541b\u3002\u611f\u89c9\u8fd9\u4e2a\u8ba9\u4eba\u66f4\u5bb9\u6613\u60f3\u5230\u7684\u662f\u5f02\u6b65\u64cd\u4f5c\uff0c\u800c\u4e0d\u662f\u56de\u8c03\u3002\u53e6\u5916\u8fd8\u6709\u4e24\u53e5\u82f1\u6587\u8ba9\u6211\u5370\u8c61\u6df1\u523b\uff1a1) If you call me, I will call you back; 2) Don't call me, I will call you. \u770b\u8d77\u6765\u597d\u50cf\u5f88\u6709\u9053\u7406\uff0c\u4f46\u662f\u4ed4\u7ec6\u4e00\u60f3\uff0c\u666e\u901a\u51fd\u6570\u4e0d\u4e5f\u53ef\u4ee5\u505a\u5230\u8fd9\u4e24\u70b9\u5417\uff1f\u6240\u4ee5\uff0c\u6211\u89c9\u5f97\u8fd9\u6837\u7684\u8bf4\u6cd5\u90fd\u4e0d\u662f\u5f88\u59a5\u5f53\uff0c\u56e0\u4e3a\u6211\u89c9\u5f97\u8fd9\u4e9b\u8bf4\u6cd5\u90fd\u6ca1\u6709\u628a\u56de\u8c03\u51fd\u6570\u7684\u7279\u70b9\u8868\u8fbe\u51fa\u6765\uff0c\u4e5f\u5c31\u662f\u90fd\u770b\u4e0d\u5230\u548c\u666e\u901a\u51fd\u6570\u5230\u5e95\u6709\u4ec0\u4e48\u5dee\u522b\u3002\u4e0d\u8fc7\uff0c\u767e\u5ea6\u767e\u79d1\u7684\u89e3\u6790\u6211\u89c9\u5f97\u8fd8\u7b97\u4e0d\u9519\uff08\u867d\u7136\u7ecf\u5e38\u5410\u69fd\u767e\u5ea6\u641c\u7d22...\uff09\uff1a\u56de\u8c03\u51fd\u6570\u5c31\u662f\u4e00\u4e2a\u901a\u8fc7\u51fd\u6570\u6307\u9488\u8c03\u7528\u7684\u51fd\u6570\u3002\u5982\u679c\u4f60\u628a\u51fd\u6570\u7684\u6307\u9488\uff08\u5730\u5740\uff09\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u53e6\u4e00\u4e2a\u51fd\u6570\uff0c\u5f53\u8fd9\u4e2a\u6307\u9488\u88ab\u7528\u6765\u8c03\u7528\u5176\u6240\u6307\u5411\u7684\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u5c31\u8bf4\u8fd9\u662f\u56de\u8c03\u51fd\u6570\u3002<\/p>\n \u4e0b\u9762\u5148\u8bf4\u8bf4\u6211\u7684\u770b\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u5148\u5728\u5b57\u9762\u4e0a\u5148\u505a\u4e2a\u5206\u89e3\uff0c\u5bf9\u4e8e\"\u56de\u8c03\u51fd\u6570\"\uff0c\u4e2d\u6587\u5176\u5b9e\u53ef\u4ee5\u7406\u89e3\u4e3a\u8fd9\u4e48\u4e24\u79cd\u610f\u601d\uff1a1) \u88ab\u56de\u8c03\u7684\u51fd\u6570\uff1b2) \u56de\u5934\u6267\u884c\u8c03\u7528\u52a8\u4f5c\u7684\u51fd\u6570\u3002\u90a3\u8fd9\u4e2a\u56de\u5934\u8c03\u7528\u53c8\u662f\u4ec0\u4e48\u9b3c\uff1f<\/p>\n \u5148\u6765\u770b\u770b\u6765\u81ea\u7ef4\u57fa\u767e\u79d1\u7684\u5bf9\u56de\u8c03\uff08Callback\uff09\u7684\u89e3\u6790\uff1aIn computer programming, a callback is any executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at a given time. This execution may be immediate as in a synchronous callback, or it might happen at a later time as in an asynchronous callback. \u4e5f\u5c31\u662f\u8bf4\uff0c\u628a\u4e00\u6bb5\u53ef\u6267\u884c\u7684\u4ee3\u7801\u50cf\u53c2\u6570\u4f20\u9012\u90a3\u6837\u4f20\u7ed9\u5176\u4ed6\u4ee3\u7801\uff0c\u800c\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u5728\u67d0\u4e2a\u65f6\u523b\u88ab\u8c03\u7528\u6267\u884c\uff0c\u8fd9\u5c31\u53eb\u505a\u56de\u8c03\u3002\u5982\u679c\u4ee3\u7801\u7acb\u5373\u88ab\u6267\u884c\u5c31\u79f0\u4e3a\u540c\u6b65\u56de\u8c03\uff0c\u5982\u679c\u5728\u4e4b\u540e\u665a\u70b9\u7684\u67d0\u4e2a\u65f6\u95f4\u518d\u6267\u884c\uff0c\u5219\u79f0\u4e4b\u4e3a\u5f02\u6b65\u56de\u8c03\u3002\u5173\u4e8e\u540c\u6b65\u548c\u5f02\u6b65\uff0c\u8fd9\u91cc\u4e0d\u4f5c\u8ba8\u8bba\uff0c\u8bf7\u67e5\u9605\u76f8\u5173\u8d44\u6599\u3002<\/p>\n \u518d\u6765\u770b\u770b\u6765\u81eaStack Overflow\u67d0\u4f4d\u5927\u795e\u7b80\u6d01\u660e\u4e86\u7684\u8868\u8ff0\uff1aA \"callback\" is any function that is called by another function which takes the first function as a parameter\u3002 \u4e5f\u5c31\u662f\u8bf4\uff0c\u51fd\u6570 F1 \u8c03\u7528\u51fd\u6570 F2 \u7684\u65f6\u5019\uff0c\u51fd\u6570 F1 \u901a\u8fc7\u53c2\u6570\u7ed9 \u51fd\u6570 F2 \u4f20\u9012\u4e86\u53e6\u5916\u4e00\u4e2a\u51fd\u6570 F3 \u7684\u6307\u9488\uff0c\u5728\u51fd\u6570 F2 \u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u51fd\u6570F2 \u8c03\u7528\u4e86\u51fd\u6570 F3\uff0c\u8fd9\u4e2a\u52a8\u4f5c\u5c31\u53eb\u505a\u56de\u8c03\uff08Callback\uff09\uff0c\u800c\u5148\u88ab\u5f53\u505a\u6307\u9488\u4f20\u5165\u3001\u540e\u9762\u53c8\u88ab\u56de\u8c03\u7684\u51fd\u6570 F3 \u5c31\u662f\u56de\u8c03\u51fd\u6570\u3002\u5230\u6b64\u5e94\u8be5\u660e\u767d\u56de\u8c03\u51fd\u6570\u7684\u5b9a\u4e49\u4e86\u5427\uff1f<\/p>\n 2. \u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u56de\u8c03\u51fd\u6570\uff1f<\/strong><\/div>\n \u5f88\u591a\u670b\u53cb\u53ef\u80fd\u4f1a\u60f3\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u50cf\u666e\u901a\u51fd\u6570\u8c03\u7528\u90a3\u6837\uff0c\u5728\u56de\u8c03\u7684\u5730\u65b9\u76f4\u63a5\u5199\u51fd\u6570\u7684\u540d\u5b57\u5462\uff1f\u8fd9\u6837\u4e0d\u4e5f\u53ef\u4ee5\u5417\uff1f\u4e3a\u4ec0\u4e48\u975e\u5f97\u7528\u56de\u8c03\u51fd\u6570\u5462\uff1f\u6709\u8fd9\u4e2a\u60f3\u6cd5\u5f88\u597d\uff0c\u56e0\u4e3a\u5728\u7f51\u4e0a\u770b\u5230\u89e3\u6790\u56de\u8c03\u51fd\u6570\u7684\u5f88\u591a\u4f8b\u5b50\uff0c\u5176\u5b9e\u5b8c\u5168\u53ef\u4ee5\u7528\u666e\u901a\u51fd\u6570\u8c03\u7528\u6765\u5b9e\u73b0\u7684\u3002\u8981\u56de\u7b54\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u5148\u6765\u4e86\u89e3\u4e00\u4e0b\u56de\u5230\u51fd\u6570\u7684\u597d\u5904\u548c\u4f5c\u7528\uff0c\u90a3\u5c31\u662f\u89e3\u8026\uff0c\u5bf9\uff0c\u5c31\u662f\u8fd9\u4e48\u7b80\u5355\u7684\u7b54\u6848\uff0c\u5c31\u662f\u56e0\u4e3a\u8fd9\u4e2a\u7279\u70b9\uff0c\u666e\u901a\u51fd\u6570\u4ee3\u66ff\u4e0d\u4e86\u56de\u8c03\u51fd\u6570\u3002\u6240\u4ee5\uff0c\u5728\u6211\u773c\u91cc\uff0c\u8fd9\u624d\u662f\u56de\u8c03\u51fd\u6570\u6700\u5927\u7684\u7279\u70b9\u3002\u6765\u770b\u770b\u7ef4\u57fa\u767e\u79d1\u4e0a\u9762\u6211\u89c9\u5f97\u753b\u5f97\u5f88\u597d\u7684\u4e00\u5f20\u56fe\u7247\u3002 \u4e0b\u9762\u4ee5\u4e00\u6bb5\u4e0d\u5b8c\u6574\u7684 C \u8bed\u8a00\u4ee3\u7801\u6765\u5448\u73b0\u4e0a\u56fe\u7684\u610f\u601d\uff1a<\/p>\n \u5b9e\u4f8b<\/p>\n #include |