{"id":9434,"date":"2023-03-05T10:27:27","date_gmt":"2023-03-05T02:27:27","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=9434"},"modified":"2024-05-05T14:18:11","modified_gmt":"2024-05-05T06:18:11","slug":"vs-%e8%ad%a6%e5%91%8a%e5%8f%af%e8%83%bd%e6%b2%a1%e6%9c%89%e4%b8%ba%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%b7%bb%e5%8a%a0%e5%ad%97%e7%ac%a6%e4%b8%b2%e9%9b%b6%e7%bb%88%e6%ad%a2%e7%ac%a6","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=9434","title":{"rendered":"VS \u8b66\u544a\u53ef\u80fd\u6ca1\u6709\u4e3a\u5b57\u7b26\u4e32\u6dfb\u52a0\u96f6\u7ec8\u6b62\u7b26"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=9434\/#%E7%8E%AF%E5%A2%83\" >\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=9434\/#%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0\" >\u95ee\u9898\u63cf\u8ff0<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E7%8E%AF%E5%A2%83\"><\/span>\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Windows SDK 10.0\uff08Windows 11\uff09<br \/>\n\u5e73\u53f0\u5de5\u5177\u96c6\uff1aVisual Studio 2022 v143<br \/>\nC \u8bed\u8a00\u6807\u51c6\uff1aC17<br \/>\n\u5b57\u7b26\u96c6\uff1aUnicode<\/p>\n<hr \/>\n<p>Debian 11\uff08arm64\uff09<br \/>\n\u7f16\u8bd1\u5668\uff1aGNU\uff08gcc\uff0910.2.1<br \/>\nC \u8bed\u8a00\u6807\u51c6\uff1aC17<br \/>\n\u7f16\u8bd1\u53c2\u6570\uff1a-std=c17 -no-pie -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Werror=format-security -Wextra -pedantic -Wimplicit-fallthrough -Wsequence-point -Wswitch-unreachable -Wswitch-enum -Wstringop-truncation -Wbool-compare -Wtautological-compare -Wfloat-equal -Wshadow=global -Wpointer-arith -Wpointer-compare -Wcast-align -Wcast-qual -Wwrite-strings -Wdangling-else -Wlogical-op -Wconversion -g -O0<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0\"><\/span>\u95ee\u9898\u63cf\u8ff0<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u4e4b\u524d\u6211\u662f\u57fa\u672c\u6ca1\u600e\u4e48\u7528 VS \u7684\uff08MSVC \u7f16\u8bd1\u5668\uff09\uff0c\u53ea\u662f\u524d\u6bb5\u65f6\u95f4\u5f00\u59cb\u5b66 Windows API \u624d\u6bd4\u8f83\u591a\u7684\u4f7f\u7528\u3002<br \/>\n\u6628\u5929\u665a\u4e0a\u8c03\u8bd5\u7a0b\u5e8f\u7684\u65f6\u5019\u9047\u5230\u4e00\u4e2a\u8b66\u544a\uff0c\u60c5\u666f\u7c7b\u4f3c\u4e0b\u9762\u7684\u4ee3\u7801<\/p>\n<pre><code class=\"language-c\">#define _CRT_SECURE_NO_WARNINGS\n#include &lt;Windows.h&gt;\n#include &lt;stdio.h&gt;\n\nint main()\n{\n    WCHAR s1[128];\n    PCWSTR s2 = L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01ABCDabcd1234&quot;;\n    memset(s1, 0, sizeof(s1));\n    wcsncpy(s1, s2, wcslen(s2));\n    wprintf(L&quot;%I64u\\n&quot;, wcslen(s1));\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/03\/image-1677982462904.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 494px; --smush-placeholder-aspect-ratio: 494\/171;\" \/><\/p>\n<p>\u7136\u540e\u5728\u67e5\u9605\u5fae\u8f6f\u6280\u672f\u6587\u6863\u4e2d\u627e\u5230\u4e86\u89e3\u91ca<\/p>\n<p>C6053<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/03\/image-1677982160111.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 895px; --smush-placeholder-aspect-ratio: 895\/702;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/03\/image-1677982202977.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 888px; --smush-placeholder-aspect-ratio: 888\/757;\" \/><\/p>\n<p>C6054<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/03\/image-1677982072745.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 897px; --smush-placeholder-aspect-ratio: 897\/907;\" \/><\/p>\n<p>\u800c\u8bb0\u5fc6\u4e2d\u4f7f\u7528 gcc \u7f16\u8bd1\u5668\u5e76\u6ca1\u6709\u9047\u5230\u8fc7\u8fd9\u79cd\u8b66\u544a\uff0c\u6240\u4ee5\u5728 gcc \u4e0b\u53c8\u8bd5\u4e86\u4e00\u4e0b<\/p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\nint main()\n{\n    char s[128];\n    const char *a = &quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01ABCDabcd1234&quot;;\n    memset(s, 0, sizeof(s));\n    strncpy(s, a, strlen(a));\n    printf(&quot;%lu\\n&quot;, strlen(s));\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/03\/image-1677982557643.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 660px; --smush-placeholder-aspect-ratio: 660\/320;\" \/><\/p>\n<p>gcc \u5e76\u6ca1\u6709\u8b66\u544a\u8fd9\u4e2a\uff0c\u5982\u679c\u771f\u7684\u8b66\u544a\u4e86\u8fd9\u4e2a\uff0c\u90a3\u80af\u5b9a\u5f97\u7ed9\u51fa\u66ff\u4ee3\u65b9\u6848\u3002MSVC \u8b66\u544a\u4e86\u5c31\u5728\u63a8\u8350\u5b83\u7684 _s \u5b89\u5168\u51fd\u6570\u4f5c\u4e3a\u66ff\u4ee3\uff0c\u800c\u4e14\u4e0a\u9762\u7684\u6587\u6863\u4e5f\u8bf4\u4e86\u201c\u53ef\u80fd\u201d\uff0c\u5e76\u4e0d\u662f\u4ee3\u7801\u771f\u7684\u6709\u95ee\u9898\uff0c\u53ea\u662f\u6f5c\u5728\u95ee\u9898\u3002\u6240\u4ee5\u6700\u7ec8\u7684\u5173\u952e\u5c31\u662f\u770b\u5f00\u53d1\u8005\u80fd\u4e0d\u80fd\u6b63\u786e\u4f7f\u7528\uff0c\u8981\u4fdd\u8bc1\u88ab\u590d\u5236\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u4e0d\u8d85\u8fc7\u5b57\u7b26\u6570\u7ec4\u7684\u5bb9\u91cf\uff0c\u5c31\u4e0d\u4f1a\u53d1\u751f\u6ea2\u51fa\uff0c\u4e5f\u5c31\u5e76\u4e0d\u9700\u8981\u4f7f\u7528\u5b89\u5168\u51fd\u6570\u3002<br \/>\n\u5728\u5fae\u8f6f\u7684\u52aa\u529b\u4e0b\uff0cC11 \u6807\u51c6\u4e2d\u52a0\u5165\u4e86\u5b89\u5168\u51fd\u6570\uff08\u53ef\u9009\u5b9e\u73b0\uff09\uff0c\u7136\u800c\u5b9e\u9645\u6b63\u9762\u652f\u6301\u7684\u5c31\u662f MSVC \u81ea\u5df1\u5427\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883 Windows SDK 10.0\uff08Windows 11\uff09 \u5e73\u53f0\u5de5\u5177\u96c6\uff1aVisual Studio 202 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-9434","post","type-post","status-publish","format-standard","hentry","category-all"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/9434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9434"}],"version-history":[{"count":0,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/9434\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}