{"id":49032,"date":"2025-07-30T14:51:40","date_gmt":"2025-07-30T06:51:40","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/49032.html"},"modified":"2025-07-30T14:51:40","modified_gmt":"2025-07-30T06:51:40","slug":"c-%e8%af%ad%e8%a8%80%e4%bd%9c%e7%94%a8%e5%9f%9f%e4%b8%8e%e5%ad%98%e5%82%a8%e6%9c%9f%e6%b7%b1%e5%ba%a6%e8%a7%a3%e6%9e%90%ef%bc%9a%e7%a9%ba%e9%97%b4%e4%b8%8e%e6%97%b6%e9%97%b4%e7%9a%84%e5%8f%8c%e9%87%8d","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/49032.html","title":{"rendered":"C \u8bed\u8a00\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u6df1\u5ea6\u89e3\u6790\uff1a\u7a7a\u95f4\u4e0e\u65f6\u95f4\u7684\u53cc\u91cd\u7ef4\u5ea6"},"content":{"rendered":"<h2>\u5f00\u7bc7&#xff1a;\u7a0b\u5e8f\u6807\u8bc6\u7b26\u7684\u65f6\u7a7a\u6cd5\u5219<\/h2>\n<p>\u5728 C \u8bed\u8a00\u4e2d&#xff0c;\u6bcf\u4e2a\u6807\u8bc6\u7b26&#xff08;\u53d8\u91cf\u3001\u51fd\u6570&#xff09;\u90fd\u9075\u5faa\u4e25\u683c\u7684 \u201c\u65f6\u7a7a\u6cd5\u5219\u201d<\/p>\n<ul>\n<li>\u4f5c\u7528\u57df&#xff08;Scope&#xff09;&#xff1a;\u5b9a\u4e49\u6807\u8bc6\u7b26\u7684 \u201c\u7a7a\u95f4\u8fb9\u754c\u201d\u2014\u2014 \u5728\u54ea\u91cc\u53ef\u89c1&#xff1f;<\/li>\n<li>\u5b58\u50a8\u671f&#xff08;Storage Duration&#xff09;&#xff1a;\u5b9a\u4e49\u6807\u8bc6\u7b26\u7684 \u201c\u65f6\u95f4\u8fb9\u754c\u201d\u2014\u2014 \u4f55\u65f6\u5b58\u5728&#xff1f;<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u4e2a\u6982\u5ff5\u770b\u4f3c\u5173\u8054&#xff0c;\u5b9e\u5219\u72ec\u7acb\u3002\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\u51fd\u6570\u5185\u7684static\u53d8\u91cf&#xff1a;\u4f5c\u7528\u57df\u5c40\u9650\u4e8e\u51fd\u6570&#xff08;\u7a7a\u95f4\u5c0f&#xff09;&#xff0c;\u4f46\u5b58\u50a8\u671f\u8d2f\u7a7f\u7a0b\u5e8f\u59cb\u7ec8&#xff08;\u65f6\u95f4\u957f&#xff09;\u3002<\/li>\n<li>\u5168\u5c40\u53d8\u91cf&#xff1a;\u4f5c\u7528\u57df\u8de8\u8d8a\u591a\u4e2a\u6587\u4ef6&#xff08;\u7a7a\u95f4\u5927&#xff09;&#xff0c;\u5b58\u50a8\u671f\u4e0e\u7a0b\u5e8f\u540c\u751f\u5171\u6b7b&#xff08;\u65f6\u95f4\u957f&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u7406\u89e3\u8fd9\u4e24\u4e2a\u6838\u5fc3\u6982\u5ff5&#xff0c;\u662f\u638c\u63e1 C \u8bed\u8a00\u5185\u5b58\u7ba1\u7406\u548c\u6a21\u5757\u5316\u7f16\u7a0b\u7684\u57fa\u7840\u3002<\/p>\n<h3>\u7b2c\u4e00\u90e8\u5206&#xff1a;\u4f5c\u7528\u57df \u2014\u2014 \u6807\u8bc6\u7b26\u7684 \u201c\u53ef\u89c1\u5730\u56fe\u201d<\/h3>\n<h4>1. \u5757\u4f5c\u7528\u57df&#xff08;Block Scope&#xff09;&#xff1a;\u6700\u5c0f\u7684\u53ef\u89c1\u5355\u5143<\/h4>\n<p>\u5b9a\u4e49&#xff1a;\u7531{}\u754c\u5b9a\u7684\u533a\u57df&#xff0c;\u5305\u62ec\u51fd\u6570\u4f53\u3001if\/for\u5757\u3001\u663e\u5f0f\u5757&#xff08;\u5982{ int temp; }&#xff09;\u3002<br \/>\n\u89c4\u5219&#xff1a;\u6807\u8bc6\u7b26\u4ece\u58f0\u660e\u70b9\u5f00\u59cb\u53ef\u89c1&#xff0c;\u81f3\u5757\u7ed3\u675f\u65f6\u5931\u6548\u3002<br \/>\n\u7279\u6027&#xff1a;<\/p>\n<ul>\n<li>\u5185\u5c42\u5757\u53ef\u58f0\u660e\u4e0e\u5916\u5c42\u540c\u540d\u7684\u6807\u8bc6\u7b26&#xff0c;\u4ea7\u751f\u906e\u853d\u6548\u5e94&#xff08;\u5916\u5c42\u540c\u540d\u6807\u8bc6\u7b26\u88ab\u9690\u85cf&#xff09;\u3002<\/li>\n<li>\u5757\u5916\u65e0\u6cd5\u8bbf\u95ee\u5757\u5185\u6807\u8bc6\u7b26&#xff08;\u7f16\u8bd1\u9519\u8bef&#xff09;\u3002<\/li>\n<\/ul>\n<h5>\u4ee3\u7801\u793a\u4f8b&#xff1a;\u5757\u4f5c\u7528\u57df\u4e0e\u906e\u853d<\/h5>\n<p>#include &lt;stdio.h&gt;<\/p>\n<p>int main() {<br \/>\n    int x &#061; 10; \/\/ \u5757\u4f5c\u7528\u57df&#xff08;main\u51fd\u6570\u4f53&#xff09;<br \/>\n    printf(&#034;Outer x: %d\\\\n&#034;, x); \/\/ \u8f93\u51fa&#xff1a;10<\/p>\n<p>    { \/\/ \u663e\u5f0f\u5757<br \/>\n        int x &#061; 20; \/\/ \u906e\u853d\u5916\u5c42x<br \/>\n        printf(&#034;Inner x: %d\\\\n&#034;, x); \/\/ \u8f93\u51fa&#xff1a;20<br \/>\n    } \/\/ x\u5728\u6b64\u5904\u9500\u6bc1<\/p>\n<p>    \/\/ printf(&#034;Inner x: %d\\\\n&#034;, x); \/\/ ERROR: x not declared in this scope<br \/>\n    return 0;<br \/>\n}<\/p>\n<h5>\u5178\u578b\u9519\u8bef&#xff1a;\u5757\u5916\u8bbf\u95ee<\/h5>\n<p>void func() {<br \/>\n    if (1) {<br \/>\n        int temp &#061; 42; \/\/ \u5757\u4f5c\u7528\u57df<br \/>\n    }<br \/>\n    printf(&#034;%d&#034;, temp); \/\/ ERROR: temp\u672a\u58f0\u660e<br \/>\n}<\/p>\n<h4>2. \u51fd\u6570\u4f5c\u7528\u57df&#xff08;Function Scope&#xff09;&#xff1a;\u6807\u7b7e\u7684\u4e13\u5c5e\u9886\u57df<\/h4>\n<p>\u5b9a\u4e49&#xff1a;\u4ec5\u9002\u7528\u4e8elabel:\u6807\u7b7e&#xff08;\u5982goto target;&#xff09;\u3002<br \/>\n\u89c4\u5219&#xff1a;\u6807\u7b7e\u5728\u6574\u4e2a\u51fd\u6570\u4f53\u5185\u53ef\u89c1&#xff0c;\u4e0d\u53d7\u5757\u8fb9\u754c\u9650\u5236\u3002<\/p>\n<h5>\u4ee3\u7801\u793a\u4f8b&#xff1a;\u51fd\u6570\u4f5c\u7528\u57df\u7684\u6807\u7b7e<\/h5>\n<p>void process() {<br \/>\n    int retry &#061; 3;<br \/>\n    while (retry &gt; 0) {<br \/>\n        if (someError()) {<br \/>\n            retry&#8211;;<br \/>\n            goto cleanup; \/\/ \u5408\u6cd5&#xff0c;\u6807\u7b7e\u5728\u51fd\u6570\u5185\u53ef\u89c1<br \/>\n        }<br \/>\n    }<br \/>\ncleanup: \/\/ \u6807\u7b7e\u4f5c\u7528\u57df\u4e3a\u6574\u4e2a\u51fd\u6570<br \/>\n    printf(&#034;Cleaning up&#8230;\\\\n&#034;);<br \/>\n}<\/p>\n<h4>3. \u6587\u4ef6\u4f5c\u7528\u57df&#xff08;File Scope&#xff09;&#xff1a;\u8de8\u5757\u7684\u5168\u5c40\u53ef\u89c1<\/h4>\n<p>\u5b9a\u4e49&#xff1a;\u5728\u51fd\u6570\u548c\u5757\u5916\u90e8\u58f0\u660e\u7684\u6807\u8bc6\u7b26&#xff0c;\u4f5c\u7528\u57df\u4ece\u58f0\u660e\u70b9\u81f3\u6587\u4ef6\u672b\u5c3e\u3002<br \/>\n\u94fe\u63a5\u5c5e\u6027&#xff1a;<\/p>\n<ul>\n<li>\u5916\u90e8\u94fe\u63a5&#xff08;\u9ed8\u8ba4&#xff09;&#xff1a;\u53ef\u88ab\u5176\u4ed6\u6587\u4ef6\u901a\u8fc7extern\u58f0\u660e\u8bbf\u95ee\u3002<\/li>\n<li>\u5185\u90e8\u94fe\u63a5&#xff08;static\u4fee\u9970&#xff09;&#xff1a;\u4ec5\u9650\u672c\u6587\u4ef6\u53ef\u89c1\u3002<\/li>\n<\/ul>\n<h5>\u4ee3\u7801\u793a\u4f8b&#xff1a;\u6587\u4ef6\u4f5c\u7528\u57df\u53d8\u91cf<\/h5>\n<p>\/\/ global.c<br \/>\nint globalVar &#061; 100; \/\/ \u5916\u90e8\u94fe\u63a5&#xff0c;\u5176\u4ed6\u6587\u4ef6\u53ef\u8bbf\u95ee<\/p>\n<p>static int staticGlobal &#061; 200; \/\/ \u5185\u90e8\u94fe\u63a5&#xff0c;\u4ec5\u9650\u672c\u6587\u4ef6\u53ef\u89c1<\/p>\n<p>\/\/ other.c<br \/>\nextern int globalVar; \/\/ \u58f0\u660e\u5916\u90e8\u94fe\u63a5\u53d8\u91cf<br \/>\nvoid useGlobal() {<br \/>\n    printf(&#034;Global var: %d\\\\n&#034;, globalVar); \/\/ \u5408\u6cd5<br \/>\n    \/\/ printf(&#034;Static global: %d\\\\n&#034;, staticGlobal); \/\/ ERROR: \u672a\u58f0\u660e<br \/>\n}<\/p>\n<h4>4. \u94fe\u63a5\u5c5e\u6027&#xff1a;\u4f5c\u7528\u57df\u7684 \u201c\u8de8\u6587\u4ef6\u901a\u884c\u8bc1\u201d<\/h4>\n<table>\n<tr>\u94fe\u63a5\u5c5e\u6027\u4f5c\u7528\u57df\u5176\u4ed6\u6587\u4ef6\u8bbf\u95ee\u58f0\u660e\u65b9\u5f0f<\/tr>\n<tbody>\n<tr>\n<td>\u5916\u90e8\u94fe\u63a5<\/td>\n<td>\u6587\u4ef6\u4f5c\u7528\u57df<\/td>\n<td>\u5141\u8bb8&#xff08;extern&#xff09;<\/td>\n<td>\u65e0static\u4fee\u9970<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u90e8\u94fe\u63a5<\/td>\n<td>\u6587\u4ef6\u4f5c\u7528\u57df<\/td>\n<td>\u7981\u6b62<\/td>\n<td>static\u4fee\u9970<\/td>\n<\/tr>\n<tr>\n<td>\u65e0\u94fe\u63a5<\/td>\n<td>\u5757 \/ \u51fd\u6570\u4f5c\u7528\u57df<\/td>\n<td>\u7981\u6b62<\/td>\n<td>\u5757\u5185\u58f0\u660e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>5. \u51fd\u6570\u539f\u578b\u4f5c\u7528\u57df&#xff1a;\u5f62\u53c2\u7684\u77ed\u6682\u5b58\u5728<\/h4>\n<p>\u5b9a\u4e49&#xff1a;\u51fd\u6570\u58f0\u660e\u4e2d\u7684\u5f62\u53c2\u5217\u8868&#xff0c;\u4ec5\u5728\u539f\u578b\u5185\u6709\u6548\u3002<\/p>\n<p>int add(int a, int b); \/\/ a\u548cb\u4ec5\u5728\u6b64\u539f\u578b\u4e2d\u53ef\u89c1&#xff0c;\u53ef\u7701\u7565\u540d\u79f0<br \/>\nint add(int, int); \/\/ \u5408\u6cd5&#xff0c;\u5f62\u53c2\u540d\u975e\u5fc5\u9700<\/p>\n<h4>\u4f5c\u7528\u57df\u6700\u4f73\u5b9e\u8df5<\/h4>\n<li>\u6700\u5c0f\u4f5c\u7528\u57df\u539f\u5219&#xff1a;\u53d8\u91cf\u58f0\u660e\u9760\u8fd1\u9996\u6b21\u4f7f\u7528\u5904&#xff0c;\u51cf\u5c11\u6c61\u67d3\u3002\n<p>void calculate() {<br \/>\n    \/\/ \u975e\u5fc5\u8981\u4e0d\u63d0\u524d\u58f0\u660e<br \/>\n    if (condition) {<br \/>\n        int result &#061; compute(); \/\/ \u4ec5\u5728if\u5757\u5185\u53ef\u89c1<br \/>\n    }<br \/>\n}<\/p>\n<\/li>\n<li>\u907f\u514d\u5168\u5c40\u53d8\u91cf\u6ee5\u7528&#xff1a;\u4f18\u5148\u4f7f\u7528\u5c40\u90e8\u53d8\u91cf\u6216\u51fd\u6570\u53c2\u6570\u3002<\/li>\n<li>\u9759\u6001\u4fee\u9970\u6587\u4ef6\u4f5c\u7528\u57df\u53d8\u91cf&#xff1a;\u82e5\u65e0\u9700\u8de8\u6587\u4ef6\u8bbf\u95ee&#xff0c;\u7528static\u9650\u5236\u94fe\u63a5\u6027\u3002<\/li>\n<h3>\u7b2c\u4e8c\u90e8\u5206&#xff1a;\u5b58\u50a8\u671f \u2014\u2014 \u6807\u8bc6\u7b26\u7684 \u201c\u751f\u547d\u5468\u671f\u56fe\u8c31\u201d<\/h3>\n<h4>1. \u81ea\u52a8\u5b58\u50a8\u671f&#xff08;Automatic&#xff09;&#xff1a;\u6808\u4e0a\u7684\u77ed\u6682\u5b58\u5728<\/h4>\n<p>\u5bf9\u8c61&#xff1a;\u5757\u4f5c\u7528\u57df\u5185\u65e0static\/extern\u7684\u53d8\u91cf&#xff08;\u542b\u5f62\u53c2&#xff09;\u3002<br \/>\n\u751f\u547d\u5468\u671f&#xff1a;<\/p>\n<ul>\n<li>\u521b\u5efa&#xff1a;\u8fdb\u5165\u5757\u65f6\u5728\u6808\u4e0a\u5206\u914d\u5185\u5b58\u3002<\/li>\n<li>\u9500\u6bc1&#xff1a;\u9000\u51fa\u5757\u65f6\u81ea\u52a8\u91ca\u653e\u5185\u5b58&#xff08;\u6808\u6307\u9488\u56de\u9000&#xff09;\u3002<br \/>\n\u7279\u6027&#xff1a;<\/li>\n<li>\u503c\u672a\u521d\u59cb\u5316\u65f6\u4e3a\u4e0d\u786e\u5b9a\u503c&#xff08;\u5783\u573e\u503c&#xff09;\u3002<\/li>\n<li>\u9ad8\u6548&#xff1a;\u5206\u914d \/ \u91ca\u653e\u4ec5\u9700\u79fb\u52a8\u6808\u6307\u9488\u3002<\/li>\n<\/ul>\n<h5>\u4ee3\u7801\u793a\u4f8b&#xff1a;\u81ea\u52a8\u5b58\u50a8\u671f\u53d8\u91cf<\/h5>\n<p>void func() {<br \/>\n    int localVar; \/\/ \u81ea\u52a8\u5b58\u50a8\u671f<br \/>\n    \/\/ printf(&#034;%d&#034;, localVar); \/\/ ERROR: \u672a\u521d\u59cb\u5316&#xff0c;\u503c\u4e0d\u786e\u5b9a<br \/>\n    localVar &#061; 42; \/\/ \u663e\u5f0f\u521d\u59cb\u5316<br \/>\n} \/\/ localVar\u5728\u6b64\u5904\u9500\u6bc1<\/p>\n<h4>2. \u9759\u6001\u5b58\u50a8\u671f&#xff08;Static&#xff09;&#xff1a;\u8de8\u8d8a\u51fd\u6570\u7684\u6301\u4e45\u5b58\u5728<\/h4>\n<p>\u5bf9\u8c61&#xff1a;<\/p>\n<ul>\n<li>\u6587\u4ef6\u4f5c\u7528\u57df\u6240\u6709\u53d8\u91cf&#xff08;\u65e0\u8bba\u662f\u5426static&#xff09;\u3002<\/li>\n<li>\u5757\u4f5c\u7528\u57df\u5e26static\u7684\u53d8\u91cf\u3002<br \/>\n\u751f\u547d\u5468\u671f&#xff1a;<\/li>\n<li>\u521b\u5efa&#xff1a;\u7a0b\u5e8f\u542f\u52a8\u65f6\u5206\u914d\u5185\u5b58&#xff08;\u5728\u9759\u6001\u5b58\u50a8\u533a&#xff09;\u3002<\/li>\n<li>\u9500\u6bc1&#xff1a;\u7a0b\u5e8f\u7ed3\u675f\u65f6\u91ca\u653e\u5185\u5b58\u3002<br \/>\n\u521d\u59cb\u5316&#xff1a;\u4ec5\u521d\u59cb\u5316\u4e00\u6b21&#xff0c;\u672a\u663e\u5f0f\u521d\u59cb\u5316\u7684\u503c\u4e3a 0&#xff08;\u6570\u503c\u578b&#xff09;\u6216NULL&#xff08;\u6307\u9488&#xff09;\u3002<\/li>\n<\/ul>\n<h5>\u7ec6\u5206\u7c7b\u578b<\/h5>\n<table>\n<tr>\u7c7b\u578b\u4f5c\u7528\u57df\u94fe\u63a5\u5c5e\u6027\u5178\u578b\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>\u5916\u90e8\u9759\u6001<\/td>\n<td>\u6587\u4ef6\u4f5c\u7528\u57df<\/td>\n<td>\u5916\u90e8\u94fe\u63a5<\/td>\n<td>\u8de8\u6587\u4ef6\u5168\u5c40\u53d8\u91cf<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u90e8\u9759\u6001<\/td>\n<td>\u6587\u4ef6\u4f5c\u7528\u57df<\/td>\n<td>\u5185\u90e8\u94fe\u63a5<\/td>\n<td>\u672c\u6587\u4ef6\u5168\u5c40\u8f85\u52a9\u53d8\u91cf<\/td>\n<\/tr>\n<tr>\n<td>\u5c40\u90e8\u9759\u6001<\/td>\n<td>\u5757\u4f5c\u7528\u57df<\/td>\n<td>\u65e0\u94fe\u63a5<\/td>\n<td>\u51fd\u6570\u5185\u6301\u4e45\u8ba1\u6570\u5668<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u4ee3\u7801\u793a\u4f8b&#xff1a;\u5c40\u90e8\u9759\u6001\u53d8\u91cf<\/h5>\n<p>int counter() {<br \/>\n    static int count &#061; 0; \/\/ \u9759\u6001\u5b58\u50a8\u671f&#xff0c;\u5757\u4f5c\u7528\u57df<br \/>\n    count&#043;&#043;;<br \/>\n    return count;<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    printf(&#034;%d\\\\n&#034;, counter()); \/\/ 1<br \/>\n    printf(&#034;%d\\\\n&#034;, counter()); \/\/ 2<br \/>\n    return 0;<br \/>\n}<\/p>\n<h4>3. \u7ebf\u7a0b\u5b58\u50a8\u671f&#xff08;Thread&#xff0c;C11&#xff09;&#xff1a;\u7ebf\u7a0b\u4e13\u5c5e\u751f\u547d\u5468\u671f<\/h4>\n<p>\u5b9a\u4e49&#xff1a;\u7528_Thread_local\u4fee\u9970&#xff0c;\u5bf9\u8c61\u4e0e\u7ebf\u7a0b\u540c\u751f\u5171\u6b7b\u3002<\/p>\n<p>_Thread_local int threadId; \/\/ \u6bcf\u4e2a\u7ebf\u7a0b\u72ec\u7acb\u5b9e\u4f8b<\/p>\n<h4>4. \u52a8\u6001\u5b58\u50a8\u671f&#xff08;Allocated&#xff09;&#xff1a;\u5806\u4e0a\u7684\u624b\u52a8\u7ba1\u7406<\/h4>\n<p>\u5bf9\u8c61&#xff1a;\u901a\u8fc7malloc\/calloc\/realloc\u5206\u914d\u7684\u5185\u5b58\u3002<br \/>\n\u751f\u547d\u5468\u671f&#xff1a;<\/p>\n<ul>\n<li>\u521b\u5efa&#xff1a;\u8c03\u7528\u5206\u914d\u51fd\u6570\u65f6&#xff08;\u5806\u5185\u5b58&#xff09;\u3002<\/li>\n<li>\u9500\u6bc1&#xff1a;\u8c03\u7528free\u65f6\u6216\u7a0b\u5e8f\u7ed3\u675f&#xff08;\u5185\u5b58\u6cc4\u6f0f\u65f6&#xff09;\u3002<br \/>\n\u98ce\u9669&#xff1a;<\/li>\n<li>\u5185\u5b58\u6cc4\u6f0f&#xff1a;\u672a\u8c03\u7528free\u3002<\/li>\n<li>\u60ac\u5782\u6307\u9488&#xff1a;\u91ca\u653e\u540e\u7ee7\u7eed\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n<h5>\u4ee3\u7801\u793a\u4f8b&#xff1a;\u52a8\u6001\u5185\u5b58\u7ba1\u7406<\/h5>\n<p>int* createArray(int size) {<br \/>\n    int* arr &#061; malloc(size * sizeof(int)); \/\/ \u521b\u5efa<br \/>\n    if (arr &#061;&#061; NULL) exit(1);<br \/>\n    return arr;<br \/>\n}<\/p>\n<p>void useArray() {<br \/>\n    int* arr &#061; createArray(5);<br \/>\n    \/\/ \u4f7f\u7528arr&#8230;<br \/>\n    free(arr); \/\/ \u9500\u6bc1<br \/>\n    arr &#061; NULL; \/\/ \u9632\u6b62\u60ac\u5782\u6307\u9488<br \/>\n}<\/p>\n<h3>\u7b2c\u4e09\u90e8\u5206&#xff1a;\u5173\u952e\u5b57\u7684\u53cc\u91cd\u89d2\u8272<\/h3>\n<h4>1. static&#xff1a;\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u7684\u8c03\u8282\u5668<\/h4>\n<h5>\u6587\u4ef6\u4f5c\u7528\u57df &#043; static&#xff1a;\u9650\u5236\u94fe\u63a5\u6027<\/h5>\n<p>static int config &#061; 100; \/\/ \u5185\u90e8\u94fe\u63a5&#xff0c;\u672c\u6587\u4ef6\u53ef\u89c1<\/p>\n<h5>\u5757\u4f5c\u7528\u57df &#043; static&#xff1a;\u5ef6\u957f\u5b58\u50a8\u671f<\/h5>\n<p>void func() {<br \/>\n    static int state &#061; 0; \/\/ \u5757\u4f5c\u7528\u57df&#xff0c;\u9759\u6001\u5b58\u50a8\u671f<br \/>\n    state&#043;&#043;;<br \/>\n}<\/p>\n<h4>2. extern&#xff1a;\u8de8\u6587\u4ef6\u7684\u58f0\u660e\u5668<\/h4>\n<p>\u4f5c\u7528&#xff1a;\u58f0\u660e\u5176\u4ed6\u6587\u4ef6\u5b9a\u4e49\u7684\u6807\u8bc6\u7b26&#xff0c;\u4e0d\u5206\u914d\u5185\u5b58\u3002<\/p>\n<p>\/\/ main.c<br \/>\nextern int sharedVar; \/\/ \u58f0\u660e\u5728other.c\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf<br \/>\nvoid main() {<br \/>\n    printf(&#034;%d\\\\n&#034;, sharedVar); \/\/ \u4f7f\u7528other.c\u4e2d\u7684\u53d8\u91cf<br \/>\n}<\/p>\n<p>\/\/ other.c<br \/>\nint sharedVar &#061; 200; \/\/ \u5b9a\u4e49<\/p>\n<h4>3. auto \u4e0e register&#xff1a;\u73b0\u4ee3 C \u7684\u8fb9\u7f18\u89d2\u8272<\/h4>\n<ul>\n<li>auto&#xff1a;\u663e\u5f0f\u58f0\u660e\u81ea\u52a8\u5b58\u50a8\u671f&#xff08;\u9ed8\u8ba4\u53ef\u7701\u7565&#xff09;\u3002\n<p>auto int temp &#061; 42; \/\/ \u7b49\u4ef7\u4e8eint temp &#061; 42;<\/p>\n<\/li>\n<li>register&#xff1a;\u5efa\u8bae\u7f16\u8bd1\u5668\u5c06\u53d8\u91cf\u5b58\u5165\u5bc4\u5b58\u5668&#xff08;\u975e\u5f3a\u5236&#xff0c;\u73b0\u4ee3\u7f16\u8bd1\u5668\u81ea\u52a8\u4f18\u5316&#xff09;\u3002<\/li>\n<\/ul>\n<h3>\u7b2c\u56db\u90e8\u5206&#xff1a;\u6838\u5fc3\u5173\u8054\u3001\u9677\u9631\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h3>\n<h4>1. \u4f5c\u7528\u57df vs \u5b58\u50a8\u671f&#xff1a;\u65f6\u7a7a\u7684\u4ea4\u7ec7\u4e0e\u72ec\u7acb<\/h4>\n<table>\n<tr>\u7279\u6027\u4f5c\u7528\u57df&#xff08;\u7a7a\u95f4&#xff09;\u5b58\u50a8\u671f&#xff08;\u65f6\u95f4&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>\u5173\u8054\u6848\u4f8b<\/td>\n<td>\u5c40\u90e8\u53d8\u91cf&#xff08;\u5757\u4f5c\u7528\u57df&#xff09;<\/td>\n<td>\u81ea\u52a8\u5b58\u50a8\u671f&#xff08;\u77ed\u751f\u547d\u5468\u671f&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u72ec\u7acb\u6848\u4f8b<\/td>\n<td>static \u5c40\u90e8\u53d8\u91cf<\/td>\n<td>\u9759\u6001\u5b58\u50a8\u671f&#xff08;\u957f\u751f\u547d\u5468\u671f&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2. \u81f4\u547d\u9677\u9631\u4e0e\u89c4\u907f<\/h4>\n<h5>\u9677\u9631 1&#xff1a;\u8fd4\u56de\u5c40\u90e8\u53d8\u91cf\u6307\u9488&#xff08;\u60ac\u5782\u6307\u9488&#xff09;<\/h5>\n<p>int* dangerous() {<br \/>\n    int localVar &#061; 42; \/\/ \u81ea\u52a8\u5b58\u50a8\u671f&#xff0c;\u51fd\u6570\u8fd4\u56de\u540e\u9500\u6bc1<br \/>\n    return &amp;localVar; \/\/ ERROR: \u8fd4\u56de\u5df2\u9500\u6bc1\u5bf9\u8c61\u7684\u5730\u5740<br \/>\n}<\/p>\n<p>\/\/ \u89c4\u907f&#xff1a;\u4f7f\u7528\u52a8\u6001\u5185\u5b58\u6216\u9759\u6001\u5c40\u90e8\u53d8\u91cf<br \/>\nint* safe() {<br \/>\n    static int staticVar &#061; 42; \/\/ \u9759\u6001\u5b58\u50a8\u671f&#xff0c;\u53ef\u8fd4\u56de\u5730\u5740<br \/>\n    return &amp;staticVar;<br \/>\n}<\/p>\n<h5>\u9677\u9631 2&#xff1a;\u5168\u5c40\u53d8\u91cf\u591a\u91cd\u5b9a\u4e49<\/h5>\n<p>file1.c<\/p>\n<p>int global &#061; 10; \/\/ \u5b9a\u4e49<\/p>\n<p>file2.c<\/p>\n<p>int global &#061; 20; \/\/ \u9519\u8bef&#xff1a;\u91cd\u590d\u5b9a\u4e49<\/p>\n<p>\u89c4\u907f&#xff1a;<\/p>\n<ul>\n<li>\u5934\u6587\u4ef6\u4e2d\u7528extern\u58f0\u660e&#xff1a;\n<p>\/\/ global.h<br \/>\nextern int global; \/\/ \u58f0\u660e&#xff0c;\u975e\u5b9a\u4e49<\/p>\n<\/li>\n<li>\u5355\u4e00\u5b9a\u4e49\u5728\u67d0\u4e2a.c\u6587\u4ef6\u4e2d\u3002<\/li>\n<\/ul>\n<h5>\u9677\u9631 3&#xff1a;\u5934\u6587\u4ef6\u4e2d\u5b9a\u4e49\u5168\u5c40\u53d8\u91cf<\/h5>\n<p>\/\/ bad.h<br \/>\nint config &#061; 100; \/\/ \u88ab\u591a\u4e2a.c\u5305\u542b\u65f6\u5bfc\u81f4\u591a\u91cd\u5b9a\u4e49<\/p>\n<p>\u89c4\u907f&#xff1a;\u5934\u6587\u4ef6\u4e2d\u53ea\u58f0\u660e\u4e0d\u5b9a\u4e49\u3002<\/p>\n<h4>3. \u5168\u5c40\u53d8\u91cf\u4f7f\u7528\u94c1\u5f8b<\/h4>\n<ul>\n<li>\u4f18\u5148\u5c40\u90e8\u53d8\u91cf&#xff1a;\u51cf\u5c11\u8026\u5408&#xff0c;\u63d0\u9ad8\u51fd\u6570\u72ec\u7acb\u6027\u3002<\/li>\n<li>\u5185\u90e8\u94fe\u63a5\u4f18\u5148&#xff1a;\u7528static\u9650\u5236\u6587\u4ef6\u4f5c\u7528\u57df\u53d8\u91cf\u3002<\/li>\n<li>\u8de8\u6587\u4ef6\u5171\u4eab&#xff1a;\u901a\u8fc7extern\u58f0\u660e &#043; \u5355\u4e00\u5b9a\u4e49\u3002<\/li>\n<\/ul>\n<h4>4. \u591a\u6587\u4ef6\u9879\u76ee\u89c4\u8303<\/h4>\n<h5>\u5934\u6587\u4ef6&#xff08;.h&#xff09;\u5185\u5bb9&#xff1a;<\/h5>\n<ul>\n<li>extern\u58f0\u660e\u5168\u5c40\u53d8\u91cf<\/li>\n<li>\u51fd\u6570\u539f\u578b<\/li>\n<li>typedef\/#define<\/li>\n<li>static inline\u51fd\u6570&#xff08;C99&#043;&#xff09;<\/li>\n<\/ul>\n<h5>\u6e90\u6587\u4ef6&#xff08;.c&#xff09;\u5185\u5bb9&#xff1a;<\/h5>\n<ul>\n<li>\u53d8\u91cf\u5b9a\u4e49&#xff08;\u5982int global;&#xff09;<\/li>\n<li>\u51fd\u6570\u5b9e\u73b0<\/li>\n<\/ul>\n<h3>\u7efc\u5408\u7ec3\u4e60\u9898<\/h3>\n<li>\n<p>\u60ac\u5782\u6307\u9488\u5206\u6790<\/p>\n<p>int *func() {<br \/>\n    int x&#061;10;<br \/>\n    return &amp;x;<br \/>\n}<br \/>\nint *p &#061; func();<br \/>\nprintf(&#034;%d&#034;, *p); \/\/ \u672a\u5b9a\u4e49\u884c\u4e3a&#xff0c;x\u5df2\u9500\u6bc1<\/p>\n<p>\u00a0<\/p>\n<p>\u98ce\u9669&#xff1a;\u8fd4\u56de\u81ea\u52a8\u5b58\u50a8\u671f\u53d8\u91cf\u7684\u5730\u5740&#xff0c;\u8bbf\u95ee\u5df2\u91ca\u653e\u5185\u5b58&#xff0c;\u53ef\u80fd\u5d29\u6e83\u6216\u8bfb\u53d6\u5783\u573e\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>\u8de8\u6587\u4ef6\u5168\u5c40\u53d8\u91cf<br \/>\nglobal.h<\/p>\n<p>extern int configValue; \/\/ \u58f0\u660e<\/p>\n<p>config.c<\/p>\n<p>int configValue &#061; 50; \/\/ \u5b9a\u4e49<\/p>\n<p>main.c<\/p>\n<p>#include &#034;global.h&#034;<br \/>\nint main() {<br \/>\n    printf(&#034;%d&#034;, configValue); \/\/ \u5408\u6cd5<br \/>\n    return 0;<br \/>\n}<\/p>\n<\/li>\n<li>\n<p>\u9759\u6001\u8ba1\u6570\u5668\u5b9e\u73b0<\/p>\n<p>int nextId() {<br \/>\n    static int id &#061; 0;<br \/>\n    return &#043;&#043;id;<br \/>\n}<\/p>\n<\/li>\n<li>\n<p>static \u4e0e extern \u517c\u5bb9\u6027<br \/>\n\u6587\u4ef6 A \u7684static int internal;\u5177\u6709\u5185\u90e8\u94fe\u63a5&#xff0c;\u6587\u4ef6 B \u7684extern int internal;\u65e0\u6cd5\u94fe\u63a5&#xff0c;\u56e0\u4e3ainternal\u5728\u6587\u4ef6 A \u4e2d\u4e0d\u53ef\u89c1\u3002<\/p>\n<\/li>\n<li>\n<p>static \u5c40\u90e8\u53d8\u91cf\u7279\u6027<\/p>\n<ul>\n<li>\u4f5c\u7528\u57df&#xff1a;counter\u51fd\u6570\u5185<\/li>\n<li>\u5b58\u50a8\u671f&#xff1a;\u7a0b\u5e8f\u5168\u7a0b<\/li>\n<li>\u521d\u59cb\u503c&#xff1a;0&#xff08;\u9759\u6001\u53d8\u91cf\u9ed8\u8ba4\u521d\u59cb\u5316&#xff09;<\/li>\n<li>\u7b2c\u4e00\u6b21\u8c03\u7528\u540e&#xff1a;1<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u52a8\u6001\u6570\u7ec4\u521d\u59cb\u5316\u4e0e\u91ca\u653e<\/p>\n<p>int* arr &#061; calloc(5, sizeof(int)); \/\/ \u5206\u914d\u5e76\u521d\u59cb\u5316\u4e3a0<br \/>\nif (arr &#061;&#061; NULL) exit(1);<br \/>\n\/\/ \u4f7f\u7528arr&#8230;<br \/>\nfree(arr);<br \/>\narr &#061; NULL;<\/p>\n<\/li>\n<li>\n<p>\u5757\u4f5c\u7528\u57df\u53d8\u91cf\u5bf9\u6bd4<\/p>\n<ul>\n<li>int a;&#xff1a;\u8fdb\u5165\u5757\u65f6\u521b\u5efa&#xff0c;\u9000\u51fa\u65f6\u9500\u6bc1&#xff0c;\u672a\u521d\u59cb\u5316\u503c\u4e0d\u786e\u5b9a\u3002<\/li>\n<li>static int b;&#xff1a;\u7a0b\u5e8f\u542f\u52a8\u65f6\u521b\u5efa&#xff0c;\u7a0b\u5e8f\u7ed3\u675f\u65f6\u9500\u6bc1&#xff0c;\u672a\u521d\u59cb\u5316\u503c\u4e3a 0&#xff0c;\u4ec5\u521d\u59cb\u5316\u4e00\u6b21\u3002<\/li>\n<\/ul>\n<\/li>\n<h3>\u7ed3\u8bed&#xff1a;\u5728\u65f6\u7a7a\u6cd5\u5219\u4e2d\u7f16\u5199\u5065\u58ee\u4ee3\u7801<\/h3>\n<p>\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u662f C \u8bed\u8a00\u7684 \u201c\u5e95\u5c42\u5951\u7ea6\u201d&#xff1a;<\/p>\n<ul>\n<li>\u4f5c\u7528\u57df\u6559\u4f1a\u6211\u4eec \u201c\u6570\u636e\u53ef\u89c1\u7684\u8fb9\u754c\u201d&#xff0c;\u907f\u514d\u547d\u540d\u6c61\u67d3\u548c\u610f\u5916\u8bbf\u95ee\u3002<\/li>\n<li>\u5b58\u50a8\u671f\u8b66\u793a\u6211\u4eec \u201c\u5185\u5b58\u751f\u5b58\u7684\u5468\u671f\u201d&#xff0c;\u9632\u6b62\u6cc4\u6f0f\u548c\u60ac\u5782\u3002<\/li>\n<\/ul>\n<p>\u638c\u63e1\u8fd9\u4e24\u4e2a\u6982\u5ff5\u7684\u6838\u5fc3&#xff0c;\u9700\u8981\u59cb\u7ec8\u7262\u8bb0&#xff1a;<\/p>\n<ul>\n<li>\u5c0f\u4f5c\u7528\u57df\u4f18\u5148&#xff0c;\u51cf\u5c11\u5168\u5c40\u72b6\u6001&#xff1b;<\/li>\n<li>\u7406\u89e3\u5b58\u50a8\u671f\u7279\u6027&#xff0c;\u5339\u914d\u751f\u547d\u5468\u671f&#xff1b;<\/li>\n<li>\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u9075\u5faa \u201c\u5206\u914d &#8211; \u4f7f\u7528 &#8211; \u91ca\u653e\u201d \u94c1\u5f8b\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u523b\u610f\u7ec3\u4e60\u548c\u7f16\u8bd1\u5668\u8b66\u544a&#xff08;\u5982-Wall -Wextra&#xff09;&#xff0c;\u9010\u6b65\u57f9\u517b \u201c\u65f6\u7a7a\u654f\u611f\u201d \u7684\u7f16\u7a0b\u601d\u7ef4&#xff0c;\u8ba9\u6bcf\u4e00\u4e2a\u6807\u8bc6\u7b26\u90fd\u5728\u6b63\u786e\u7684\u65f6\u95f4\u51fa\u73b0\u5728\u6b63\u786e\u7684\u5730\u65b9&#xff0c;\u8fd9\u662f\u5199\u51fa\u5065\u58ee C \u7a0b\u5e8f\u7684\u5fc5\u7ecf\u4e4b\u8def\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb254\u6b21\u3002file1.c\/\/ \u5b9a\u4e49file2.c\/\/ \u9519\u8bef\uff1a\u91cd\u590d\u5b9a\u4e49\u89c4\u907f\u5934\u6587\u4ef6\u4e2d\u7528extern\u58f0\u660e\uff1a\/\/ \u58f0\u660e\uff0c\u975e\u5b9a\u4e49\u5355\u4e00\u5b9a\u4e49\u5728\u67d0\u4e2a.c\u6587\u4ef6\u4e2d\u3002\/\/ bad.h\/\/ \u88ab\u591a\u4e2a.c\u5305\u542b\u65f6\u5bfc\u81f4\u591a\u91cd\u5b9a\u4e49\u89c4\u907f\uff1a\u5934\u6587\u4ef6\u4e2d\u53ea\u58f0\u660e\u4e0d\u5b9a\u4e49\u3002\u4f5c\u7528\u57df\u6559\u4f1a\u6211\u4eec \u201c\u6570\u636e\u53ef\u89c1\u7684\u8fb9\u754c\u201d\uff0c\u907f\u514d\u547d\u540d\u6c61\u67d3\u548c\u610f\u5916\u8bbf\u95ee\u3002\u5b58\u50a8\u671f\u8b66\u793a\u6211\u4eec \u201c\u5185\u5b58\u751f\u5b58\u7684\u5468\u671f\u201d\uff0c\u9632\u6b62\u6cc4\u6f0f\u548c\u60ac\u5782\u3002\u5c0f\u4f5c\u7528\u57df\u4f18\u5148\uff0c\u51cf\u5c11\u5168\u5c40\u72b6\u6001\uff1b\u7406\u89e3\u5b58\u50a8\u671f\u7279\u6027\uff0c\u5339\u914d\u751f\u547d\u5468\u671f\uff1b\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u9075\u5faa \u201c\u5206\u914d &#8211; \u4f7f\u7528 &#8211; \u91ca\u653e\u201d \u94c1\u5f8b\u3002\u901a\u8fc7\u523b\u610f\u7ec3\u4e60\u548c\u7f16\u8bd1\u5668\u8b66\u544a\uff08\u5982\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[174,190,305,124],"topic":[],"class_list":["post-49032","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-190","tag-305","tag-124"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C \u8bed\u8a00\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u6df1\u5ea6\u89e3\u6790\uff1a\u7a7a\u95f4\u4e0e\u65f6\u95f4\u7684\u53cc\u91cd\u7ef4\u5ea6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/49032.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C \u8bed\u8a00\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u6df1\u5ea6\u89e3\u6790\uff1a\u7a7a\u95f4\u4e0e\u65f6\u95f4\u7684\u53cc\u91cd\u7ef4\u5ea6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb254\u6b21\u3002file1.c\/\/ \u5b9a\u4e49file2.c\/\/ \u9519\u8bef\uff1a\u91cd\u590d\u5b9a\u4e49\u89c4\u907f\u5934\u6587\u4ef6\u4e2d\u7528extern\u58f0\u660e\uff1a\/\/ \u58f0\u660e\uff0c\u975e\u5b9a\u4e49\u5355\u4e00\u5b9a\u4e49\u5728\u67d0\u4e2a.c\u6587\u4ef6\u4e2d\u3002\/\/ bad.h\/\/ \u88ab\u591a\u4e2a.c\u5305\u542b\u65f6\u5bfc\u81f4\u591a\u91cd\u5b9a\u4e49\u89c4\u907f\uff1a\u5934\u6587\u4ef6\u4e2d\u53ea\u58f0\u660e\u4e0d\u5b9a\u4e49\u3002\u4f5c\u7528\u57df\u6559\u4f1a\u6211\u4eec \u201c\u6570\u636e\u53ef\u89c1\u7684\u8fb9\u754c\u201d\uff0c\u907f\u514d\u547d\u540d\u6c61\u67d3\u548c\u610f\u5916\u8bbf\u95ee\u3002\u5b58\u50a8\u671f\u8b66\u793a\u6211\u4eec \u201c\u5185\u5b58\u751f\u5b58\u7684\u5468\u671f\u201d\uff0c\u9632\u6b62\u6cc4\u6f0f\u548c\u60ac\u5782\u3002\u5c0f\u4f5c\u7528\u57df\u4f18\u5148\uff0c\u51cf\u5c11\u5168\u5c40\u72b6\u6001\uff1b\u7406\u89e3\u5b58\u50a8\u671f\u7279\u6027\uff0c\u5339\u914d\u751f\u547d\u5468\u671f\uff1b\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u9075\u5faa \u201c\u5206\u914d - \u4f7f\u7528 - \u91ca\u653e\u201d \u94c1\u5f8b\u3002\u901a\u8fc7\u523b\u610f\u7ec3\u4e60\u548c\u7f16\u8bd1\u5668\u8b66\u544a\uff08\u5982\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/49032.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-30T06:51:40+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/49032.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/49032.html\",\"name\":\"C \u8bed\u8a00\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u6df1\u5ea6\u89e3\u6790\uff1a\u7a7a\u95f4\u4e0e\u65f6\u95f4\u7684\u53cc\u91cd\u7ef4\u5ea6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-30T06:51:40+00:00\",\"dateModified\":\"2025-07-30T06:51:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/49032.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/49032.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/49032.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C \u8bed\u8a00\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u6df1\u5ea6\u89e3\u6790\uff1a\u7a7a\u95f4\u4e0e\u65f6\u95f4\u7684\u53cc\u91cd\u7ef4\u5ea6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C \u8bed\u8a00\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u6df1\u5ea6\u89e3\u6790\uff1a\u7a7a\u95f4\u4e0e\u65f6\u95f4\u7684\u53cc\u91cd\u7ef4\u5ea6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/49032.html","og_locale":"zh_CN","og_type":"article","og_title":"C \u8bed\u8a00\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u6df1\u5ea6\u89e3\u6790\uff1a\u7a7a\u95f4\u4e0e\u65f6\u95f4\u7684\u53cc\u91cd\u7ef4\u5ea6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb254\u6b21\u3002file1.c\/\/ \u5b9a\u4e49file2.c\/\/ \u9519\u8bef\uff1a\u91cd\u590d\u5b9a\u4e49\u89c4\u907f\u5934\u6587\u4ef6\u4e2d\u7528extern\u58f0\u660e\uff1a\/\/ \u58f0\u660e\uff0c\u975e\u5b9a\u4e49\u5355\u4e00\u5b9a\u4e49\u5728\u67d0\u4e2a.c\u6587\u4ef6\u4e2d\u3002\/\/ bad.h\/\/ \u88ab\u591a\u4e2a.c\u5305\u542b\u65f6\u5bfc\u81f4\u591a\u91cd\u5b9a\u4e49\u89c4\u907f\uff1a\u5934\u6587\u4ef6\u4e2d\u53ea\u58f0\u660e\u4e0d\u5b9a\u4e49\u3002\u4f5c\u7528\u57df\u6559\u4f1a\u6211\u4eec \u201c\u6570\u636e\u53ef\u89c1\u7684\u8fb9\u754c\u201d\uff0c\u907f\u514d\u547d\u540d\u6c61\u67d3\u548c\u610f\u5916\u8bbf\u95ee\u3002\u5b58\u50a8\u671f\u8b66\u793a\u6211\u4eec \u201c\u5185\u5b58\u751f\u5b58\u7684\u5468\u671f\u201d\uff0c\u9632\u6b62\u6cc4\u6f0f\u548c\u60ac\u5782\u3002\u5c0f\u4f5c\u7528\u57df\u4f18\u5148\uff0c\u51cf\u5c11\u5168\u5c40\u72b6\u6001\uff1b\u7406\u89e3\u5b58\u50a8\u671f\u7279\u6027\uff0c\u5339\u914d\u751f\u547d\u5468\u671f\uff1b\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u9075\u5faa \u201c\u5206\u914d - \u4f7f\u7528 - \u91ca\u653e\u201d \u94c1\u5f8b\u3002\u901a\u8fc7\u523b\u610f\u7ec3\u4e60\u548c\u7f16\u8bd1\u5668\u8b66\u544a\uff08\u5982\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/49032.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-30T06:51:40+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/49032.html","url":"https:\/\/www.wsisp.com\/helps\/49032.html","name":"C \u8bed\u8a00\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u6df1\u5ea6\u89e3\u6790\uff1a\u7a7a\u95f4\u4e0e\u65f6\u95f4\u7684\u53cc\u91cd\u7ef4\u5ea6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-30T06:51:40+00:00","dateModified":"2025-07-30T06:51:40+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/49032.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/49032.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/49032.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C \u8bed\u8a00\u4f5c\u7528\u57df\u4e0e\u5b58\u50a8\u671f\u6df1\u5ea6\u89e3\u6790\uff1a\u7a7a\u95f4\u4e0e\u65f6\u95f4\u7684\u53cc\u91cd\u7ef4\u5ea6"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/49032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=49032"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/49032\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=49032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=49032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=49032"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=49032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}