{"id":583,"date":"2025-11-28T16:46:27","date_gmt":"2025-11-28T08:46:27","guid":{"rendered":"https:\/\/hsiang.cc\/?p=583"},"modified":"2025-11-27T16:49:45","modified_gmt":"2025-11-27T08:49:45","slug":"c-%e8%aa%9e%e8%a8%80%e8%a8%bb%e8%a7%a3%e5%a4%a7%e8%a7%a3%e5%af%86%ef%bc%9a-vs-%e8%a9%b2%e6%80%8e%e9%ba%bc%e9%81%b8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/hsiang.cc\/?p=583","title":{"rendered":"[C \u8a9e\u8a00]\u8a3b\u89e3\u5927\u89e3\u5bc6\uff1a\/* *\/ vs \/\/ \u8a72\u600e\u9ebc\u9078\uff1f"},"content":{"rendered":"<p>\u5728\u5b78\u7fd2 C \u8a9e\u8a00\u7684\u904e\u7a0b\u4e2d\uff0c\u4f60\u662f\u5426\u66fe\u7d93\u56f0\u60d1\u904e\uff1a\u70ba\u4ec0\u9ebc\u6709\u4e9b\u7a0b\u5f0f\u78bc\u7528 <code>\/\/<\/code> \u8a3b\u89e3\uff0c\u6709\u4e9b\u537b\u7528 <code>\/* *\/<\/code>\uff1f\u54ea\u4e00\u7a2e\u6bd4\u8f03\u597d\uff1f\u9019\u500b\u770b\u4f3c\u7c21\u55ae\u7684\u554f\u984c\uff0c\u5176\u5be6\u85cf\u8457\u4e0d\u5c11\u5b78\u554f\u3002\u4eca\u5929\uff0c\u8b93\u6211\u5011\u4e00\u8d77\u6df1\u5165\u63a2\u8a0e\u9019\u5169\u7a2e\u8a3b\u89e3\u65b9\u5f0f\u7684\u512a\u7f3a\u9ede\uff0c\u5e6b\u52a9\u4f60\u5728\u4e0d\u540c\u60c5\u5883\u4e0b\u505a\u51fa\u6700\u4f73\u9078\u64c7\uff01<\/p>\n<hr \/>\n<h4>\ud83d\udd0d \u5169\u7a2e\u8a3b\u89e3\u65b9\u5f0f\u7684\u6b77\u53f2\u80cc\u666f<\/h4>\n<p>\u5728\u958b\u59cb\u6bd4\u8f03\u4e4b\u524d\uff0c\u5148\u4e86\u89e3\u4e00\u4e0b\u6b77\u53f2\uff1a<code>\/* *\/<\/code> \u662f C \u8a9e\u8a00\u6700\u65e9\u671f\uff08C89\/C90 \u6a19\u6e96\uff09\u5c31\u5b58\u5728\u7684\u8a3b\u89e3\u65b9\u5f0f\uff0c\u800c <code>\/\/<\/code> \u5247\u662f\u5f9e C++ \u501f\u9451\u904e\u4f86\uff0c\u76f4\u5230 C99 \u6a19\u6e96\u624d\u6b63\u5f0f\u7d0d\u5165 C \u8a9e\u8a00\u3002\u9019\u500b\u6b77\u53f2\u5dee\u7570\u4e5f\u89e3\u91cb\u4e86\u70ba\u4ec0\u9ebc\u5728\u67d0\u4e9b\u820a\u7cfb\u7d71\u6216\u5d4c\u5165\u5f0f\u958b\u767c\u4e2d\uff0c<code>\/* *\/<\/code> \u4ecd\u7136\u4f54\u64da\u4e3b\u5c0e\u5730\u4f4d\u3002<\/p>\n<h4>\ud83d\udcca \u8a73\u7d30\u6bd4\u8f03\uff1a\u512a\u7f3a\u9ede\u5206\u6790<\/h4>\n<p><!--more--><\/p>\n<p><strong><code>\/* *\/<\/code> (\u5340\u584a\u8a3b\u89e3) \u7684\u7279\u6027\uff1a<\/strong><\/p>\n<p><strong>\u512a\u9ede\uff1a<\/strong><br \/>\n- \u2705 <strong>\u6700\u4f73\u76f8\u5bb9\u6027<\/strong>\uff1a\u6240\u6709 C \u7de8\u8b6f\u5668\u90fd\u652f\u63f4\uff0c\u7121\u8ad6\u591a\u8001\u820a<br \/>\n- \u2705 <strong>\u8de8\u591a\u884c\u81ea\u7531<\/strong>\uff1a\u9069\u5408\u64b0\u5beb\u9577\u7bc7\u7684\u51fd\u6578\u8aaa\u660e\u6216\u6f14\u7b97\u6cd5\u89e3\u91cb<br \/>\n- \u2705 <strong>\u884c\u5167\u8a3b\u89e3<\/strong>\uff1a\u53ef\u4ee5\u5728\u7a0b\u5f0f\u78bc\u4e2d\u9593\u63d2\u5165\u8a3b\u89e3\uff0c\u4f8b\u5982 <code>x = a \/* \u4e2d\u9593\u8a3b\u89e3 *\/ + b;<\/code><br \/>\n- \u2705 <strong>\u6587\u4ef6\u5316\u6a19\u6e96<\/strong>\uff1a\u8a31\u591a\u6587\u4ef6\u751f\u6210\u5de5\u5177\uff08\u5982 Doxygen\uff09\u504f\u597d\u9019\u7a2e\u683c\u5f0f<\/p>\n<p><strong>\u7f3a\u9ede\uff1a<\/strong><br \/>\n- \u274c <strong>\u7121\u6cd5\u5de2\u72c0\u4f7f\u7528<\/strong>\uff1a\u9019\u662f\u6700\u5927\u7684\u75db\u9ede\uff01\u7576\u4f60\u60f3\u8a3b\u89e3\u6389\u4e00\u6bb5\u5df2\u7d93\u5305\u542b <code>\/* *\/<\/code> \u7684\u7a0b\u5f0f\u78bc\u6642\uff0c\u6703\u5c0e\u81f4\u7de8\u8b6f\u932f\u8aa4<br \/>\n- \u274c <strong>\u5bb9\u6613\u51fa\u932f<\/strong>\uff1a\u5fd8\u8a18\u95dc\u9589 <code>*\/<\/code> \u53ef\u80fd\u5c0e\u81f4\u5927\u6bb5\u7a0b\u5f0f\u78bc\u610f\u5916\u88ab\u8a3b\u89e3<br \/>\n- \u274c <strong>\u9664\u932f\u4e0d\u4fbf<\/strong>\uff1a\u5feb\u901f\u8a3b\u89e3\/\u53d6\u6d88\u8a3b\u89e3\u6642\u4e0d\u5982 <code>\/\/<\/code> \u65b9\u4fbf<\/p>\n<pre><code class=\"language-c line-numbers\">\/* \u5916\u5c64\u8a3b\u89e3\u958b\u59cb\n   int x = 10;\n   \/* \u9019\u88e1\u60f3\u518d\u8a3b\u89e3 *\/ \/\/ \u274c \u7de8\u8b6f\u5668\u6703\u5728\u9019\u88e1\u7d50\u675f\u8a3b\u89e3\n   int y = 20;  \/\/ \u9019\u884c\u4e0d\u6703\u88ab\u8a3b\u89e3\uff01\n*\/\n<\/code><\/pre>\n<p><strong><code>\/\/<\/code> (\u55ae\u884c\u8a3b\u89e3) \u7684\u7279\u6027\uff1a<\/strong><\/p>\n<p><strong>\u512a\u9ede\uff1a<\/strong><br \/>\n- \u2705 <strong>\u7c21\u6f54\u76f4\u89c0<\/strong>\uff1a\u4e00\u773c\u5c31\u80fd\u770b\u51fa\u8a3b\u89e3\u7bc4\u570d<br \/>\n- \u2705 <strong>\u53ef\u4ee5\u5de2\u72c0<\/strong>\uff1a\u8a3b\u89e3\u5305\u542b <code>\/\/<\/code> \u7684\u7a0b\u5f0f\u78bc\u5b8c\u5168\u6c92\u554f\u984c<br \/>\n- \u2705 <strong>\u9664\u932f\u53cb\u5584<\/strong>\uff1a\u5feb\u901f\u8a3b\u89e3\/\u53d6\u6d88\u8a3b\u89e3\u975e\u5e38\u65b9\u4fbf<br \/>\n- \u2705 <strong>\u66f4\u5b89\u5168<\/strong>\uff1a\u4e0d\u6703\u56e0\u70ba\u5fd8\u8a18\u95dc\u9589\u800c\u5f71\u97ff\u5f8c\u7e8c\u7a0b\u5f0f\u78bc<br \/>\n- \u2705 <strong>\u73fe\u4ee3\u6a19\u6e96<\/strong>\uff1aC99 \u4e4b\u5f8c\u7684\u6b63\u5f0f\u6a19\u6e96\uff0c\u6240\u6709\u73fe\u4ee3\u7de8\u8b6f\u5668\u90fd\u652f\u63f4<\/p>\n<p><strong>\u7f3a\u9ede\uff1a<\/strong><br \/>\n- \u274c <strong>\u591a\u884c\u9700\u91cd\u8907<\/strong>\uff1a\u6bcf\u4e00\u884c\u90fd\u8981\u52a0 <code>\/\/<\/code>\uff0c\u7a0d\u5fae\u7e41\u7463<br \/>\n- \u274c <strong>\u76f8\u5bb9\u6027\u554f\u984c<\/strong>\uff1a\u6975\u5c11\u6578\u53e4\u8001\u7de8\u8b6f\u5668\u53ef\u80fd\u4e0d\u652f\u63f4\uff08\u73fe\u5728\u5e7e\u4e4e\u4e0d\u5b58\u5728\uff09<\/p>\n<pre><code class=\"language-c line-numbers\">\/\/ \u9019\u662f\u55ae\u884c\u8a3b\u89e3\n\/\/ \u591a\u884c\u8a3b\u89e3\u9700\u8981\n\/\/ \u6bcf\u884c\u90fd\u52a0 \/\/\n\/\/ \u4f46\u53ef\u4ee5\u5b89\u5168\u5de2\u72c0\n\n\/\/ int old_code() {\n\/\/     \/\/ \u9019\u88e1\u6709\u820a\u8a3b\u89e3  \u2705 \u5b8c\u5168\u6c92\u554f\u984c\n\/\/     return 0;\n\/\/ }\n<\/code><\/pre>\n<h4>\ud83c\udfaf \u5be6\u52d9\u61c9\u7528\u5efa\u8b70<\/h4>\n<p>\u6839\u64da\u591a\u5e74\u7684\u958b\u767c\u7d93\u9a57\uff0c\u6211\u5efa\u8b70\u63a1\u7528\u300c\u6df7\u5408\u7b56\u7565\u300d\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th><strong>\u4f7f\u7528\u5834\u666f<\/strong><\/th>\n<th><strong>\u63a8\u85a6\u65b9\u5f0f<\/strong><\/th>\n<th><strong>\u7406\u7531<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u55ae\u884c\u8aaa\u660e<\/td>\n<td><code>\/\/<\/code><\/td>\n<td>\u7c21\u6f54\u660e\u77ad<\/td>\n<\/tr>\n<tr>\n<td>\u51fd\u6578\u6587\u4ef6\u8a3b\u89e3<\/td>\n<td><code>\/* *\/<\/code><\/td>\n<td>\u7b26\u5408\u6587\u4ef6\u5316\u6a19\u6e96<\/td>\n<\/tr>\n<tr>\n<td>\u6a94\u6848\u982d\u8aaa\u660e<\/td>\n<td><code>\/* *\/<\/code><\/td>\n<td>\u50b3\u7d71\u6163\u4f8b\uff0c\u7f8e\u89c0<\/td>\n<\/tr>\n<tr>\n<td>\u5feb\u901f\u9664\u932f<\/td>\n<td><code>\/\/<\/code><\/td>\n<td>\u65b9\u4fbf\u5feb\u901f\u958b\u95dc<\/td>\n<\/tr>\n<tr>\n<td>\u884c\u5c3e\u8a3b\u89e3<\/td>\n<td><code>\/\/<\/code><\/td>\n<td>\u66f4\u6e05\u6670\u6613\u8b80<\/td>\n<\/tr>\n<tr>\n<td>\u591a\u884c\u6f14\u7b97\u6cd5\u8aaa\u660e<\/td>\n<td><code>\/* *\/<\/code><\/td>\n<td>\u8996\u89ba\u4e0a\u66f4\u6574\u9f4a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\ud83d\udca1 \u5be6\u6230\u7bc4\u4f8b<\/h4>\n<pre><code class=\"language-c line-numbers\">\/**\n * \u2705 \u63a8\u85a6\uff1a\u51fd\u6578\u6587\u4ef6\u7528 \/* *\/\n * \u8a08\u7b97\u9663\u5217\u5e73\u5747\u503c\n * @param arr \u6574\u6578\u9663\u5217\n * @param size \u9663\u5217\u5927\u5c0f\n * @return \u5e73\u5747\u503c\uff08\u6d6e\u9ede\u6578\uff09\n *\/\ndouble calculate_average(int arr[], int size) {\n    \/\/ \u2705 \u63a8\u85a6\uff1a\u55ae\u884c\u8aaa\u660e\u7528 \/\/\n    int sum = 0;  \/\/ \u7d2f\u52a0\u7e3d\u548c\n\n    for (int i = 0; i &lt; size; i++) {\n        sum += arr[i];\n    }\n\n    \/\/ \u2705 \u63a8\u85a6\uff1a\u9664\u932f\u6642\u7528 \/\/\n    \/\/ printf(\"Debug: sum = %d\\n\", sum);\n\n    return (double)sum \/ size;\n}\n\n\/\/ \u274c \u907f\u514d\uff1a\u7528 \/* *\/ \u8a3b\u89e3\u5305\u542b \/* *\/ \u7684\u7a0b\u5f0f\u78bc\n\/*\nvoid old_function() {\n    int x = 10; \/* \u820a\u8a3b\u89e3 *\/  \/\/ \u9019\u6703\u5c0e\u81f4\u932f\u8aa4\uff01\n}\n*\/\n\n\/\/ \u2705 \u6b63\u78ba\uff1a\u7528 \/\/ \u8a3b\u89e3\u5305\u542b\u4efb\u4f55\u5167\u5bb9\u90fd\u5b89\u5168\n\/\/ void old_function() {\n\/\/     int x = 10; \/* \u820a\u8a3b\u89e3 *\/  \/\/ \u5b8c\u5168\u6c92\u554f\u984c\n\/\/ }\n<\/code><\/pre>\n<h4>\ud83c\udfe2 \u4e0d\u540c\u5c08\u6848\u7684\u6163\u4f8b<\/h4>\n<p><strong>Linux Kernel \u98a8\u683c\uff1a<\/strong><br \/>\n\u504f\u597d <code>\/* *\/<\/code>\uff0c\u4e26\u6709\u56b4\u683c\u7684\u591a\u884c\u8a3b\u89e3\u683c\u5f0f\uff1a<\/p>\n<pre><code class=\"language-c line-numbers\">\/*\n * \u9019\u662f Linux Kernel \u98a8\u683c\u7684\n * \u591a\u884c\u8a3b\u89e3\u683c\u5f0f\n *\/\n<\/code><\/pre>\n<p><strong>\u73fe\u4ee3\u958b\u6e90\u5c08\u6848\uff1a<\/strong><br \/>\n\u591a\u6578\u6df7\u7528\uff0c\u4ee5 <code>\/\/<\/code> \u70ba\u4e3b\u8981\u8a3b\u89e3\u65b9\u5f0f\uff0c<code>\/* *\/<\/code> \u7528\u65bc\u6587\u4ef6\u5316\u3002<\/p>\n<p><strong>\u5d4c\u5165\u5f0f\u7cfb\u7d71\uff1a<\/strong><br \/>\n\u70ba\u4e86\u6700\u5927\u76f8\u5bb9\u6027\uff0c\u901a\u5e38\u512a\u5148\u4f7f\u7528 <code>\/* *\/<\/code>\u3002<\/p>\n<h4>\u26a0\ufe0f \u5e38\u898b\u9677\u9631<\/h4>\n<ol>\n<li><strong>\u5de2\u72c0\u8a3b\u89e3\u9677\u9631\uff1a<\/strong><\/li>\n<\/ol>\n<pre><code class=\"language-c line-numbers\">\/* \u8a3b\u89e3\u958b\u59cb\n   \/* \u60f3\u518d\u8a3b\u89e3\u9019\u88e1 *\/  \/\/ \u274c \u5916\u5c64\u8a3b\u89e3\u5728\u9019\u88e1\u7d50\u675f\n   \u9019\u884c\u4e0d\u6703\u88ab\u8a3b\u89e3\uff01\n*\/\n<\/code><\/pre>\n<ol start=\"2\">\n<li><strong>\u5fd8\u8a18\u95dc\u9589\u8a3b\u89e3\uff1a<\/strong><\/li>\n<\/ol>\n<pre><code class=\"language-c line-numbers\">\/* \u958b\u59cb\u8a3b\u89e3\nint function1() { return 1; }\nint function2() { return 2; }\n\/\/ \u5fd8\u8a18\u5beb *\/\uff0c\u4e0b\u9762\u7684\u7a0b\u5f0f\u78bc\u90fd\u88ab\u8a3b\u89e3\u4e86\uff01\n<\/code><\/pre>\n<ol start=\"3\">\n<li><strong>\u5b57\u4e32\u4e2d\u7684\u8a3b\u89e3\u7b26\u865f\uff1a<\/strong><\/li>\n<\/ol>\n<pre><code class=\"language-c line-numbers\">char *str = \"http:\/\/example.com\";  \/\/ \u2705 \u6c92\u554f\u984c\nchar *comment = \"\/* \u9019\u4e0d\u662f\u8a3b\u89e3 *\/\";  \/\/ \u2705 \u4e5f\u6c92\u554f\u984c\n<\/code><\/pre>\n<hr \/>\n<p><strong>\u7d50\u5c3e\uff1a<\/strong><\/p>\n<p>\u9078\u64c7 <code>\/* *\/<\/code> \u9084\u662f <code>\/\/<\/code> \u4e26\u6c92\u6709\u7d55\u5c0d\u7684\u5c0d\u932f\uff0c\u91cd\u8981\u7684\u662f\uff1a<br \/>\n1. <strong>\u4e86\u89e3\u5404\u81ea\u7684\u512a\u7f3a\u9ede<\/strong><br \/>\n2. <strong>\u6839\u64da\u4f7f\u7528\u5834\u666f\u9078\u64c7<\/strong><br \/>\n3. <strong>\u4fdd\u6301\u5718\u968a\u98a8\u683c\u4e00\u81f4<\/strong><\/p>\n<p>\u5728\u73fe\u4ee3 C \u958b\u767c\u4e2d\uff0c\u6211\u500b\u4eba\u5efa\u8b70\u4ee5 <code>\/\/<\/code> \u4f5c\u70ba\u65e5\u5e38\u8a3b\u89e3\u7684\u4e3b\u529b\uff0c\u914d\u5408 <code>\/* *\/<\/code> \u8655\u7406\u6587\u4ef6\u5316\u9700\u6c42\u3002\u9019\u6a23\u65e2\u80fd\u4eab\u53d7 <code>\/\/<\/code> \u7684\u4fbf\u5229\u6027\uff0c\u53c8\u80fd\u4fdd\u6301\u5c08\u696d\u7684\u6587\u4ef6\u98a8\u683c\u3002<\/p>\n<p>\u4f60\u7684\u5c08\u6848\u4e2d\u504f\u597d\u54ea\u7a2e\u8a3b\u89e3\u65b9\u5f0f\u5462\uff1f\u6709\u6c92\u6709\u9047\u904e\u56e0\u70ba\u8a3b\u89e3\u65b9\u5f0f\u800c\u8e29\u5230\u7684\u5751\uff1f\u6b61\u8fce\u5728\u4e0b\u65b9\u7559\u8a00\u5206\u4eab\u4f60\u7684\u7d93\u9a57\uff0c\u8b93\u6211\u5011\u4e00\u8d77\u4ea4\u6d41\u5b78\u7fd2\uff01<\/p>\n<p>\u5e0c\u671b\u9019\u7bc7\u6587\u7ae0\u80fd\u5e6b\u52a9\u60a8\u548c\u8b80\u8005\u66f4\u6df1\u5165\u7406\u89e3 C \u8a9e\u8a00\u8a3b\u89e3\u7684\u9078\u64c7\u7b56\u7565\uff01\u5982\u679c\u9700\u8981\u8abf\u6574\u8a9e\u6c23\u3001\u589e\u52a0\u7bc4\u4f8b\u6216\u4fee\u6539\u4efb\u4f55\u90e8\u5206\uff0c\u6b61\u8fce\u96a8\u6642\u544a\u8a34\u6211 \ud83d\ude0a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5b78\u7fd2 C \u8a9e\u8a00\u7684\u904e\u7a0b\u4e2d\uff0c\u4f60\u662f\u5426\u66fe\u7d93\u56f0\u60d1\u904e\uff1a\u70ba\u4ec0\u9ebc\u6709\u4e9b\u7a0b\u5f0f\u78bc\u7528 \/\/ \u8a3b\u89e3\uff0c\u6709\u4e9b &hellip; <a href=\"https:\/\/hsiang.cc\/?p=583\">\u95b1\u8b80\u5168\u6587 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[15],"tags":[586,588,583,587,582,584,585],"class_list":{"0":"post-583","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-prog","7":"tag-c99","8":"tag-coding-style","9":"tag-c","12":"tag-584","13":"tag-585"},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/hsiang.cc\/index.php?rest_route=\/wp\/v2\/posts\/583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hsiang.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hsiang.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hsiang.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hsiang.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=583"}],"version-history":[{"count":3,"href":"https:\/\/hsiang.cc\/index.php?rest_route=\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":586,"href":"https:\/\/hsiang.cc\/index.php?rest_route=\/wp\/v2\/posts\/583\/revisions\/586"}],"wp:attachment":[{"href":"https:\/\/hsiang.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hsiang.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hsiang.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}