{"id":564,"date":"2023-11-26T15:34:16","date_gmt":"2023-11-26T07:34:16","guid":{"rendered":"https:\/\/himpqblog.cn\/?p=564"},"modified":"2023-11-26T15:34:16","modified_gmt":"2023-11-26T07:34:16","slug":"c-void%e4%b8%8e%e5%87%bd%e6%95%b0%e6%8c%87%e9%92%88%e7%9a%84%e6%8e%a2%e8%ae%a8","status":"publish","type":"post","link":"https:\/\/himpqblog.cn\/index.php\/archives\/564","title":{"rendered":"C++ void*\u4e0e\u51fd\u6570\u6307\u9488\u7684\u63a2\u8ba8"},"content":{"rendered":"\n<p>\u5341\u5206\u597d\u5947Python\u7684ctypes\u662f\u5982\u4f55\u76f4\u63a5\u8c03\u7528\u672a\u77e5\u7c7b\u578b\u7684\u51fd\u6570\u6307\u9488\u7684\u3002<\/p>\n\n\n\n<p>\u4e8e\u662f\u751f\u6210\u4e86\u4e00\u4e2adll\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"833\" height=\"558\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image.png\" alt=\"\" class=\"wp-image-566\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image.png 833w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-300x201.png 300w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-768x514.png 768w\" sizes=\"auto, (max-width: 833px) 100vw, 833px\" \/><\/figure>\n\n\n\n<p>\uff08test\u51fd\u6570\u5ffd\u7565\u4e0d\u770b\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"563\" height=\"392\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-1.png\" alt=\"\" class=\"wp-image-567\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-1.png 563w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-1-300x209.png 300w\" sizes=\"auto, (max-width: 563px) 100vw, 563px\" \/><\/figure>\n\n\n\n<p>\u53d1\u73b0char\u7c7b\u578b\u548cbool\u7c7b\u578b\u8fd4\u56de\u7684\u6570\u636e\u90fd\u7c7b\u4f3c\u4e00\u4e2a\u6307\u9488\uff0c\u800c\u5c1d\u8bd5\u7ed9\u8be5\u51fd\u6570\u66f4\u591a\u7684\u53c2\u6570\u6216\u66f4\u5c11\u7684\u53c2\u6570\u5c06\u4f1a\u53d1\u751f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"304\" height=\"143\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-2.png\" alt=\"\" class=\"wp-image-570\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-2.png 304w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-2-300x141.png 300w\" sizes=\"auto, (max-width: 304px) 100vw, 304px\" \/><\/figure>\n\n\n\n<p>\u8bf4\u660ectypes\u8c03\u7528dll\u51fd\u6570\u5927\u81f4\u662f\u5ffd\u7565\u4e86\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\uff08\u53ef\u80fd\uff1f\u6291\u6216\u662f\u63a8\u65ad\uff09:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"451\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-3-1024x451.png\" alt=\"\" class=\"wp-image-571\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-3-1024x451.png 1024w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-3-300x132.png 300w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-3-768x338.png 768w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-3.png 1389w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>ctypes\u7684\u6e90\u7801\u4e2d\u53d1\u73b0address\u4e8b\u5b9e\u4e0a\u662f\u4e00\u4e2avoid*\uff08\u5373\u4efb\u610f\u6307\u9488\uff09\u7684\u73a9\u610f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">About &#8220;void*&#8221;<\/h2>\n\n\n\n<p>void*\u53ef\u8c13\u4e00\u4e2a\u795e\u5947\u7684\u4e1c\u897f\uff0c\u5728C++\u8fd9\u4e2a\u5904\u5904\u5f3a\u7c7b\u578b\uff0c\u4e0d\u77e5\u9053\u7c7b\u578b\u51e0\u4e4e\u5bf8\u6b65\u96be\u884c\u7684\u5730\u65b9\u5374\u80fd\u5bb9\u7eb3\u4e0b\u4efb\u610f\u7684\u7c7b\u578b\u3002\u5b9e\u9645\u4e0a\u8fd9\u4e2a\u4e1c\u897f\u4e5f\u6ca1\u5565\u795e\u5947\u7684\uff0cvoid\u672c\u6765\u8868\u793a\u7684\u5c31\u662f\u672a\u77e5\u7c7b\u578b\uff0c\u53ea\u662f\u7ecf\u5e38\u5f53\u4f5c\u7a7a\u6765\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>void*\u4e0d\u8fc7\u662f\u4e00\u4e2a\u6307\u5411\u4efb\u610f\u6570\u636e\u7c7b\u578b\u7684\u6307\u9488\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"544\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-4-1024x544.png\" alt=\"\" class=\"wp-image-572\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-4-1024x544.png 1024w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-4-300x159.png 300w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-4-768x408.png 768w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-4.png 1123w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u5982\u4e0a\u9762\u7684void*\u6307\u5411\u4e86\u5185\u5b58\u76840x01\uff0c\u4f46\u662f\u4e0d\u77e5\u9053\u8be5\u5185\u5b58\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\uff0c\u6240\u4ee5\u4f60\u8981\u4f7f\u7528void*\u6307\u5411\u7684\u5185\u5b58\u5b58\u50a8\u7684\u6570\u636e\u65f6\u9700\u5f3a\u5236\u8f6c\u6362\u4e3a\u5b83\u5b9e\u9645\u7684\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u8fd9\u79cd\u8f6c\u6362\u5b9e\u9645\u4e0a\u662funsafe\u7684\uff0c\u5982\u679cvoid*\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u4e86\u4e00\u4e2a\u7a7a\u5185\u5b58\u3001\u5176\u4ed6\u7a0b\u5e8f\u7684\u5185\u5b58\u7b49\u7b49\uff0c\u6240\u4ee5Know first do later\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">void* meets functions<\/h2>\n\n\n\n<p>\u5f53void*\u78b0\u4e0a\u51fd\u6570\uff0c\u4e00\u5207\u90fd\u597d\u73a9\u8d77\u6765\u4e86\u3002<\/p>\n\n\n\n<p>\u5c31\u50cf\u4e0a\u6587\u6240\u8bf4\uff0cvoid*\u53ef\u4ee5\u5b58\u5f88\u591a\u4e1c\u897f\uff0c\u51fd\u6570\u5f53\u7136\u4e5f\u53ef\u4ee5\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u5e73\u65f6\u6240\u8bf4\u7684\u51fd\u6570\u6307\u9488\u4e00\u822c\u90fd\u8fd9\u6837\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"414\" height=\"70\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-5.png\" alt=\"\" class=\"wp-image-573\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-5.png 414w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-5-300x51.png 300w\" sizes=\"auto, (max-width: 414px) 100vw, 414px\" \/><\/figure>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u5b9a\u4e49\u4ed6\u7684\u6307\u9488\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"355\" height=\"35\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-6.png\" alt=\"\" class=\"wp-image-574\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-6.png 355w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-6-300x30.png 300w\" sizes=\"auto, (max-width: 355px) 100vw, 355px\" \/><\/figure>\n\n\n\n<p>\u4ea6\u6216\u8005\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"385\" height=\"46\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-7.png\" alt=\"\" class=\"wp-image-575\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-7.png 385w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-7-300x36.png 300w\" sizes=\"auto, (max-width: 385px) 100vw, 385px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>\u7136\u540e\u53ef\u4ee5\u8fd9\u6837\u5b9a\u4e49\u4e00\u4e2a\u6307\u5411add\u7684\u51fd\u6570\u6307\u9488\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"124\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-8.png\" alt=\"\" class=\"wp-image-576\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-8.png 462w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-8-300x81.png 300w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u65f6ptr\u5c31\u7b49\u540c\u4e8eadd123\u7684\u522b\u540d\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"433\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-9.png\" alt=\"\" class=\"wp-image-577\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-9.png 675w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-9-300x192.png 300w\" sizes=\"auto, (max-width: 675px) 100vw, 675px\" \/><\/figure>\n\n\n\n<p>\u5982\u4e0a\u56fe\uff0c\u5f53\u6211\u4eec\u5f3a\u5236\u628aadd123\u8f6c\u6362\u4e3a\u4e00\u4e2avoid*\u6307\u9488\uff08\u6307\u9488\u672c\u8d28\u4e0a\u662f\u4e00\u4e32\u6570\u5b57\uff09\uff0c\u8f93\u51fa\u5c31\u4f1a\u53d8\u6210\u6307\u9488\u7684\u4e8c\u8fdb\u5236\u8f6c\u6210\u6574\u6570\uff08\u56e0\u4e3a%d\u4ee3\u8868\u6574\u6570\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"505\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-10.png\" alt=\"\" class=\"wp-image-578\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-10.png 607w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-10-300x250.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/figure>\n\n\n\n<p>\u6b64\u65f6\u518d\u5c06ptr2\uff08void* ptr2 = (void*) add123;\uff09\u5f3a\u5236\u8f6c\u6362\u4e3aaddPtr\u7c7b\u578b\u7684\u6570\u636e\uff0c\u518d\u8c03\u7528\uff0c\u6210\u529f\u8f93\u51fa579\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5957\u5a03<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"449\" height=\"178\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-13.png\" alt=\"\" class=\"wp-image-581\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-13.png 449w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-13-300x119.png 300w\" sizes=\"auto, (max-width: 449px) 100vw, 449px\" \/><\/figure>\n\n\n\n<p>\u6211\u4eec\u5199\u4e86\u4e00\u4e2a\u6a21\u677f\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u53ef\u4ee5\u4f20\u5165\u4e00\u4e2a\u6307\u9488<strong><em>fPtr<\/em><\/strong>\uff0c\u5e76\u63a5\u4e0a<em><strong>\u4efb\u610f\u6570\u636e<\/strong><\/em>\uff08\u4f8b\u5982int, int, char&#8230;\uff09\uff0c\u968f\u540e\u5b9a\u4e49\u4e86funcPtr\u4e3a\u4e00\u4e2a\u8fd4\u56de\u503c\u4e3avoid*\uff0c\u53c2\u6570\u4e3a<strong><em>\u4f20\u5165\u7684\u4efb\u610f\u6570\u636e<\/em><\/strong>\u7684\u7c7b\u578b\uff0c\u6700\u540e\u5f3a\u5236\u8f6c\u6362<strong><em>fPtr<\/em><\/strong>\u4e3a<strong><em>funcPtr<\/em><\/strong>\u7c7b\u578b\u7684\u6570\u636e\u5e76\u8c03\u7528\u5b83\u5e76\u8fd4\u56de\u503c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"658\" height=\"404\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-14.png\" alt=\"\" class=\"wp-image-582\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-14.png 658w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-14-300x184.png 300w\" sizes=\"auto, (max-width: 658px) 100vw, 658px\" \/><\/figure>\n\n\n\n<p>\u8c03\u7528\u5b83\uff0c\u6210\u529f\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u53ef\u80fd\u4f1a\u6709\u7591\u60d1\uff1a\u660e\u660erunFunc\u4e2d\u8c03\u7528\u5f3a\u5236\u8f6c\u6362\u7684\u6570\u636e\u4e3avoid*\uff0c\u4e3a\u4f55\u6700\u540e\u8fd4\u56de\u8f93\u51fa\u8fd8\u662fint\u7684456\uff1f\u4e0d\u5e94\u8be5\u662f\u6307\u5411int\u6570\u636e456\u7684\u6307\u9488\u5417\uff1f<\/p>\n\n\n\n<p>\u6ca1\u6709\u9519\uff0c\u56e0\u4e3avoid*\u5b58\u50a8\u4e86\u539f\u672c\u8fd4\u56de456\u7684int\u6570\u636e\uff0c\u76f8\u5f53\u4e8e\u5f3a\u5236\u5c06int 456\u8f6c\u6210\u4e86void* 456\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"510\" height=\"299\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-15.png\" alt=\"\" class=\"wp-image-583\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-15.png 510w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-15-300x176.png 300w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\" \/><\/figure>\n\n\n\n<p>\u6b64\u65f6\u6211\u4eec\u591a\u7ed9\u53c2\u6570\u4e0d\u4f1a\u4ea7\u751f\u7ed3\u679c\u4e0a\u7684\u504f\u5dee\uff0c\u4f46\u662f\u5c11\u7ed9\u53c2\u6570\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"504\" height=\"302\" src=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-16.png\" alt=\"\" class=\"wp-image-584\" srcset=\"https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-16.png 504w, https:\/\/himpqblog.cn\/wp-content\/uploads\/2023\/11\/image-16-300x180.png 300w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/figure>\n\n\n\n<p>\u53ef\u80fd\u56e0\u4e3a\u6307\u9488\u8d8a\u754c\u4e86\u5bfc\u81f4add123\u6267\u884c\u7684\u52a0\u6cd5\u8fd0\u7b97\u7684\u6570\u636e\u53d8\u6210\u4e86\u91ce\u6307\u9488\u7684\u6570\u636e\u6291\u6216\u662f\u91ce\u6307\u9488\u672c\u8eab\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4e0a\u4e0a\u9762\u7531\u4e8evoid*\u7684\u5b58\u50a8\u7a7a\u95f4\u5f88\u5c0f\uff0c\u4e00\u65e6\u8fd4\u56de\u7684\u6570\u636e\u662f\u4e00\u4e2a\u8d85\u51fa\u8be5\u7c7b\u578b\u5b58\u50a8\u8303\u56f4\u7684\u6570\u636e\u5c06\u83b7\u53d6\u4e0d\u5230\u6570\u636e\uff0c\u4f8b\u5982\u4e00\u4e9b\u5bf9\u8c61\u3002\u3002\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5341\u5206\u597d\u5947Python\u7684ctypes\u662f\u5982\u4f55\u76f4\u63a5\u8c03\u7528\u672a\u77e5\u7c7b\u578b\u7684\u51fd\u6570\u6307\u9488\u7684\u3002 \u4e8e\u662f\u751f\u6210\u4e86\u4e00\u4e2adll\uff1a \uff08test\u51fd\u6570 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-564","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=564"}],"version-history":[{"count":2,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/564\/revisions"}],"predecessor-version":[{"id":586,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/564\/revisions\/586"}],"wp:attachment":[{"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himpqblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}