{
  "version": "https://jsonfeed.org/version/1", 
  "title": "C", 
  "description": "", 
  "home_page_url": "https://www.v2ex.com/go/c", 
  "feed_url": "https://www.v2ex.com/feed/c.json", 
  "icon": "https://cdn.v2ex.com/navatar/72b3/2a1f/57_large.png?m=1575483197", 
  "favicon": "https://cdn.v2ex.com/navatar/72b3/2a1f/57_normal.png?m=1575483197", 
  "items": [
    {
      "author": {
        "url": "https://www.v2ex.com/member/REEE0121", 
        "name": "REEE0121", 
        "avatar": "https://cdn.v2ex.com/gravatar/b4debb0ede1b1c36d17e89223b85f211?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1200308", 
      "title": "\u5404\u4f4d\u5927\u4f6c\uff0c C \u8a9e\u8a00\u8a72\u600e\u9ebc\u7df4\u7fd2\u554a", 
      "id": "https://www.v2ex.com/t/1200308", 
      "date_published": "2026-03-23T02:50:10+00:00", 
      "content_html": "RT \uff0c\u6a13\u4e3b\u9019\u4e94\u5929\u7121\u804a\u770b\u5230 C \u8a9e\u8a00\uff0c\u65bc\u662f\u958b\u59cb\u81ea\u5b78\u4e4b\u8def\u3002\u5230\u73fe\u5728\u5df2\u7d93\u5b78\u5230\u5faa\u74b0\uff0c\u8acb\u554f\u5404\u4f4d\u5927\u4f6c\uff0c\u6bcf\u65e5\u7df4\u7fd2\u8a72\u53bb\u54ea\u88e1\u627e\u554a\uff1f"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/echoechoin", 
        "name": "echoechoin", 
        "avatar": "https://cdn.v2ex.com/gravatar/3ab077207617a690f7006905713e2164?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1182913", 
      "date_modified": "2026-01-04T02:46:02+00:00", 
      "content_html": "<h2>\u73b0\u8c61: <code>gdb bt</code> \u5361\u5728 <code>spinlock_unlock()</code> \u4f4d\u7f6e\u3002</h2>\n<ol>\n<li>\n<p>\u67e5\u4e86\u534a\u5929\u4ee3\u7801\uff0c\u6211\u7684\u6bcf\u4e00\u4e2a\u9501\u90fd\u6ca1\u6709\u95ee\u9898\u3002\u7ed9\u6211\u770b\u5410\u8840\u4e86\u3002</p>\n</li>\n<li>\n<p>\u6700\u540e\u6ca1\u8f99\u4e86\u7075\u673a\u4e00\u52a8 <code>gdb disassemble</code> \u53d1\u73b0\u8fd9\u91cc\u6b7b\u5faa\u73af\u4e86\uff1a</p>\n</li>\n</ol>\n<p><img alt=\"gdb disassemble\" class=\"embedded_image\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"https://i.imgur.com/V3uhfWo.png\"/></p>\n<p>\u539f\u6765\u662f\u4e00\u4e2a\u6807\u5fd7\u4f4d\u6ca1\u6709\u8bbe\u7f6e\u4e3a volatile \uff0c\u4ee3\u7801\u88ab\u4f18\u5316\u4e86\u3002\u5927\u6982\u7684\u4ee3\u7801\u5982\u4e0b\uff1a</p>\n<pre><code class=\"language-c++\">while (true) {\n    // \u591a\u7ebf\u7a0b\u4e2d\u53ef\u4ee5\u88ab\u4fee\u6539\u7684\u4e00\u4e2a\u6807\u5fd7\n    if (flags_1 == STATUS_1) { \n        continue\n    }\n    // \u5176\u4ed6\u903b\u8f91\n    // ... ...\n}\n</code></pre>\n<p>\u4f46\u662f\u4e3a\u4ec0\u4e48\u4e0d\u662f\u5fc5\u73b0\u7684 BUG \u5462\uff1f AI \u7ed9\u4e86\u4e00\u5806\u89e3\u91ca\uff0c\u4f46\u662f\u6ca1\u600e\u4e48\u770b\u61c2\u3002</p>\n", 
      "date_published": "2026-01-04T02:45:46+00:00", 
      "title": "\u5206\u4eab\u4e00\u4e2a\u4ee3\u7801\u4f18\u5316\u5bfc\u81f4\u7684\u6b7b\u5faa\u73af", 
      "id": "https://www.v2ex.com/t/1182913"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/nlzy", 
        "name": "nlzy", 
        "avatar": "https://cdn.v2ex.com/avatar/9135/b320/107263_large.png?m=1770902731"
      }, 
      "url": "https://www.v2ex.com/t/1157154", 
      "title": "\u4eba\u518d\u7b28\u8fd8\u80fd\u5199\u4e0d\u51fa\u5185\u5b58\u5b89\u5168\u7684 C\uff1f", 
      "id": "https://www.v2ex.com/t/1157154", 
      "date_published": "2025-09-04T11:08:09+00:00", 
      "content_html": "<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a\u7a7a\u6307\u9488\u4e0d\u80fd\u89e3\u5f15\u7528\uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a\u8d85\u51fa\u5b58\u50a8\u671f\u7684\u5bf9\u8c61\u7684\u6307\u9488\u4e0d\u80fd\u89e3\u5f15\u7528\uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a alloc \u51fa\u6765\u7684\u6307\u9488\u9700\u8981 free \u4e00\u6b21\uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a alloc \u51fa\u6765\u7684\u6307\u9488\u4e0d\u80fd\u8d8a\u754c\u8bfb\u53d6\u548c\u5199\u5165\uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a malloc \u51fa\u6765\u7684\u5185\u5b58\u9700\u8981\u521d\u59cb\u5316\u624d\u80fd\u8bfb\u53d6\uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a free \u53ea\u80fd\u7528\u5728 alloc \u51fa\u6765\u7684\u6307\u9488\u4e0a\uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a free'ed / realloc'ed \u7684\u6307\u9488\u4e0d\u80fd\u518d\u6b21 free \uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a\u91cd\u7528 free'ed / realloc'ed \u7684\u5b58\u50a8\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a realloc \u8fd4\u56de NULL \u65f6\u539f\u6709\u6307\u9488\u4ecd\u9700 free \u4e00\u6b21\uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a memcpy memmove \u7684\u76ee\u6807\u7f13\u51b2\u533a\u7684\u5927\u5c0f\u9700\u8981\u8db3\u591f\u5927\uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a memcpy \u7684\u4e24\u6bb5\u5185\u5b58\u533a\u57df\u4e0d\u80fd\u91cd\u53e0\uff1f</p>\n<p>\u4eba\u518d\u7b28\u8fd8\u80fd\u5b66\u4e0d\u4f1a strcpy strlen puts printf(\"%s\"...) \u53ea\u80fd\u7528\u5728\u5e26 '\\0' \u7ec8\u7ed3\u7b26\u7684\u5b57\u7b26\u4e32\u4e0a\uff1f</p>\n<p>...</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/cj323", 
        "name": "cj323", 
        "avatar": "https://cdn.v2ex.com/gravatar/55d8713a4741083ba73747a518298a1f?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1155444", 
      "title": "\u60f3\u5ff5 C", 
      "id": "https://www.v2ex.com/t/1155444", 
      "date_published": "2025-08-28T02:16:55+00:00", 
      "content_html": "<p>\u5fcd\u4e0d\u4f4f\u60f3\u8d77\u5b83</p>\n<p>\u60f3\u8d77\u5b83\u9aa8\u5b50\u91cc\u7684\u81ea\u7531\uff0c\u653e\u8361\uff0c\u751a\u81f3\u5371\u9669</p>\n<p>\u6211\u5bb3\u6015\u5374\u53c8\u5174\u594b</p>\n<p>\u5b83\u6ca1\u6709\u8fb9\u754c\u611f\uff0c\u4f46\u5b83\u7684\u6307\u9488\u80fd\u5e26\u6211\u53bb\u522b\u4eba\u6839\u672c\u60f3\u8c61\u4e0d\u4e86\u7684\u73af\u5883</p>\n<p>\u5b83\u7ed9\u4e0d\u4e86\u5b89\u5168\u611f\uff0c\u4f46\u5b83\u8dd1\u8d77\u6765\u6c38\u8fdc\u662f\u6700\u5feb\u6700\u8f7b\u677e\u7684</p>\n<p>\u5b83\u7684\u4e16\u754c\u91cc\u6ca1\u6709\u89c4\u77e9\uff0c\u6ca1\u6709\u9650\u5236\uff0c\u66f4\u6ca1\u6709\u968f\u6ce2\u9010\u6d41\u7684\u6d6e\u534e</p>\n<p>\u5b83\u80fd\u968f\u65f6\u80fd\u505a\u5b83\u60f3\u505a\u7684\uff0c\u8981\u5b83\u60f3\u8981\u7684</p>\n<p>C \uff0c\u6211\u60f3\u4f60\u4e86</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/cnbatch", 
        "name": "cnbatch", 
        "avatar": "https://cdn.v2ex.com/gravatar/7eb06cdf719fb364a1dfbbaefc4f9d36?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1151667", 
      "date_modified": "2025-08-11T12:44:24+00:00", 
      "content_html": "\u901b reddit \u7684\u65f6\u5019\u89c1\u5230\u8fd9\u4e2a\u5e16\u5b50\uff0c\u81ea\u79f0\u7528 C \u8bed\u8a00\uff08 C23 \u6807\u51c6\uff09\u7ec3\u624b\uff1a<br /><br /><a target=\"_blank\" href=\"https://www.reddit.com/r/C_Programming/s/liueGRtmXs\" rel=\"nofollow noopener\">https://www.reddit.com/r/C_Programming/s/liueGRtmXs</a><br /><br />\u8ba8\u8bba\u5f53\u4e2d\u6709\u4eba\u63d0\u5230 _Generic \u6216\u8bb8\u633a\u6709\u7528\uff0c\u539f OP \u8ba4\u4e3a nullptr \u6bd4 NULL \u66f4\u597d\u3002<br /><br />C11 \u6807\u51c6\u5df2\u7ecf\u63a8\u51fa\u5341\u51e0\u5e74\u4e86\uff0c\u8fd9\u4e2a _Generic \u7528\u5f97\u591a\u4e0d\u591a\uff1f\u6bd5\u7adf C23 \u5f15\u5165 nullptr \uff0c\u5c31\u662f\u56e0\u4e3a _Generic \u7684\u7f18\u6545\uff08 N3042 \u63d0\u6848\uff09<br /><br />\u7136\u540e\u539f\u5e16\u8fd8\u6709\u4eba\u89c9\u5f97 _Generic \u8fd9\u4e2a\u540d\u5b57\u592a\u7cdf\u7cd5\u4e86\u3002\u6211\u89c9\u5f97\u4e5f\u662f\uff0c\u641e\u51fa\u597d\u51e0\u4e2a\u4e0b\u5212\u7ebf\u5f00\u5934\u7684\u5927\u5c0f\u5199\u6df7\u5408\u5173\u952e\u5b57\uff0c\u7528\u8d77\u6765\u5f88\u4e0d\u65b9\u4fbf\u3002<br /><br />\u987a\u4fbf\u4e00\u63d0\uff0c\u539f OP \u7684\u7ec3\u624b\u9879\u76ee\u7528\u7684\u662f xmake \u3002<br />\u6211\u8bb0\u5f97 xmake \u4f5c\u8005\u4e5f\u5728 V \u7ad9\uff0c\u7ed9\u4f60\u4e00\u4e2a\u5927\u8d5e\uff0c\u4f60\u7684\u9879\u76ee\u53c8\u5e2e\u4e86\u4e00\u4e2a\u4eba\u3002", 
      "date_published": "2025-08-11T12:40:48+00:00", 
      "title": "C11 \u7684 _Generic\uff0c\u73b0\u5b9e\u5f53\u4e2d\u7528\u5f97\u591a\u4e0d\u591a\uff1f\uff08\u5c24\u5176\u662f\u516c\u53f8\u9879\u76ee\uff09", 
      "id": "https://www.v2ex.com/t/1151667"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/mikewang", 
        "name": "mikewang", 
        "avatar": "https://cdn.v2ex.com/avatar/b728/8030/81681_large.png?m=1683726911"
      }, 
      "url": "https://www.v2ex.com/t/1133223", 
      "date_modified": "2025-05-21T04:11:46+00:00", 
      "content_html": "<p>\u6700\u8fd1\u5728\u628a\u6211\u7528 C \u5199\u7684\u4e00\u6279 Linux \u5de5\u5177\u79fb\u690d\u5230 Windows \u4e0a\uff0c\u5728\u5b57\u7b26\u7f16\u7801\u4e0a\u9047\u5230\u4e86\u5927\u5751\u3002</p>\n<hr/>\n<p>\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a\u6570\u6587\u4ef6\u5c42\u7ea7\u3002</p>\n<p>\u5728 Linux \u4e0a\uff0c\u6211\u4eec\u6570\u659c\u6760\u6570\u91cf\u5c31\u597d\u3002</p>\n<p>\u5728 Windows \u4e0a\uff0c\u518d\u52a0\u4e0a\u53cd\u659c\u6760\uff0c\u5e94\u8be5\u5c31\u597d\u4e86\u3002\u2014\u2014\u6211\u662f\u8fd9\u6837\u60f3\u7684\u3002</p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n\nint main(int argc, char *argv[]) {\n    int level;\n    const char *p;\n\n    if (argc &lt; 2) {\n        return 1;\n    }\n\n    for (level = 0, p = argv[1]; *p; p++) {\n        if (*p == '/' || *p == '\\\\') {\n            level++;\n        }\n    }\n\n    printf(\"%d\\n\", level);\n\n    return 0;\n}\n</code></pre>\n<p>\u7528 MinGW \u7684 GCC \u7f16\u8bd1\u4e00\u4e0b\uff0c\u7136\u540e\u8dd1\u51e0\u4e2a\u7528\u4f8b\uff1a</p>\n<pre><code class=\"language-batch\">gcc -o getlevel.exe getlevel.c\n</code></pre>\n<pre><code>C:\\&gt;getlevel C:\\\u6d59\u6c5f\u7701\\\u5b81\u6ce2\u5e02\\\u5317\u4ed1\u533a\\\u5c0f\u6e2f\u8857\u9053.txt\n4\n\nC:\\&gt;getlevel C:\\\u6d59\u6c5f\u7701\\\u5b81\u6ce2\u5e02\\\u5317\u4ed1\u533a\\\u5927\u78b6\u8857\u9053.txt\n5\n\n</code></pre>\n<p>\u5929\u584c\u4e86\uff0c\u8fd9\u4e48\u7b80\u5355\u7684\u4ee3\u7801\u7adf\u7136\u51fa\u4e86 bug \u3002</p>\n<hr/>\n<p>\u539f\u6765 <code>\u78b6</code> \u7684 \u7f16\u7801\u662f <code>{0xb4, 0x5c}</code>\uff0c\u5176\u4e2d <code>0x5c</code> \u548c\u53cd\u659c\u6760\u7684 ASCII \u7f16\u7801\u4e00\u6a21\u4e00\u6837\u3002</p>\n<p>GBK \u7684\u7b2c\u4e00\u5b57\u8282\u517c\u5bb9 ASCII \uff0c\u4f46\u7b2c\u4e8c\u5b57\u8282\u7684\u8303\u56f4\u662f <code>0x40</code> ~ <code>0xfe</code>\uff0c\u4e0e ASCII \u7684 <code>0x00</code> ~ <code>0x7f</code> \u91cd\u53e0\u3002BUG \u5c31\u8fd9\u4e48\u8bde\u751f\u4e86\u3002</p>\n<p>UTF-8 \u6ca1\u6709\u8fd9\u4e2a\u95ee\u9898\u7684\u539f\u56e0\u662f\uff1a\u53ea\u8981\u5b57\u8282\u8303\u56f4\u5728 <code>0x00</code> ~ <code>0x7f</code>\uff0c\u90a3\u4e48\u5c31\u4e00\u5b9a\u662f ASCII \uff0c\u56e0\u4e3a\u540e\u7eed\u5b57\u8282\u90fd\u907f\u5f00\u4e86\u8fd9\u4e2a\u8303\u56f4\u3002\u867d\u7136\u4e2d\u6587\u7f16\u7801\u6bd4 GB \u7cfb\u5217\u957f\u4e86\uff0c\u4f46\u662f\u8fd9\u4e2a\u8bbe\u8ba1\u786e\u5b9e\u7701\u4e86\u5f88\u591a\u4e8b\u3002\u5305\u62ec <code>strstr()</code> <code>strcmp()</code> \u4e4b\u7c7b\u7684\u90fd\u4e0d\u4f1a\u51fa\u73b0\u5947\u5947\u602a\u602a\u7684 bug \u3002</p>\n<hr/>\n<p>\u6216\u8bb8\u6211\u5e94\u8be5\u4f7f\u7528 <code>wmain()</code> \u7136\u540e\u83b7\u53d6 <code>wchar_t</code>\uff0c\u4f46\u662f <code>wmain()</code> \u662f Windows \u7279\u6709\u7684\u4e1c\u897f\uff0c\u8fd9\u6837\u505a\u5c31\u6ca1\u6cd5\u548c Linux \u516c\u7528\u540c\u4e00\u5957\u4ee3\u7801\u4e86\u3002\u76ee\u524d\u52a0\u4e0a\u4e86 <code>mbtowc()</code> \u4f5c\u4e3a\u4fee\u590d\u3002\u539f\u672c\u7b80\u6d01\u7684\u4ee3\u7801\u53d8\u5f97\u5341\u5206\u590d\u6742\uff1a\uff08</p>\n<p>\u8bf4\u5230\u8fd9\u53c8\u4e0d\u5f97\u4e0d\u5410\u69fd\u4e0b Windows \u7684\u5404\u79cd\u5947\u602a API \u4e86\uff0c\u4e0d\u77e5\u9053\u5b83\u662f\u5982\u4f55\u5b58\u6d3b\u5230\u73b0\u5728\u7684...</p>\n", 
      "date_published": "2025-05-21T04:11:36+00:00", 
      "title": "\u5751\u7239\u7684 GBK\uff1a\u5927\u5bb6\u90fd\u5e94\u8be5\u53bb\u7528 UTF-8", 
      "id": "https://www.v2ex.com/t/1133223"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/henix", 
        "name": "henix", 
        "avatar": "https://cdn.v2ex.com/gravatar/41ecaf675f9a963ac47aec132fd468a6?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1127752", 
      "title": "\u5206\u4eab\u4e00\u4e2a\u7528 AI \u5b66\u4e60 C \u8bed\u8a00\u7684\u4f8b\u5b50", 
      "id": "https://www.v2ex.com/t/1127752", 
      "date_published": "2025-04-24T04:32:48+00:00", 
      "content_html": "<p>\u4ee5\u4e0b\u6765\u81ea\u6211\u8ddf DeepSeek \u7684\u5bf9\u8bdd\uff1a</p>\n<h3>\u6211\u7684\u63d0\u95ee</h3>\n<p>\u6211\u8981\u4e3a C \u8bed\u8a00\u7684 qsort \u7f16\u5199\u4e00\u4e2a\u6bd4\u8f83\u51fd\u6570\uff0c\u6bd4\u8f83\u4e24\u4e2a <code>uint64_t</code> \uff0c\u8003\u8651\u4ee5\u4e0b\u4e24\u79cd\u5b9e\u73b0\uff1a</p>\n<pre><code class=\"language-c\">int qcmp_uint64(const void* pa, const void* pb) {\n  uint64_t a = *(uint64_t*)pa;\n  uint64_t b = *(uint64_t*)pb;\n  if (a &lt; b) return -1;\n  if (a &gt; b) return 1;\n  return 0;\n}\n</code></pre>\n<pre><code class=\"language-c\">int qcmp_uint64_2(const void* pa, const void* pb) {\n  uint64_t a = *(uint64_t*)pa;\n  uint64_t b = *(uint64_t*)pb;\n  return a - b;\n}\n</code></pre>\n<p>\u4ece\u76f4\u89c9\u4e0a\u770b\uff0c\u4f3c\u4e4e\u7b2c\u4e8c\u79cd\u5b9e\u73b0\u6548\u7387\u66f4\u9ad8\uff0c\u4f46\u7531\u4e8e\u6574\u6570\u76f8\u51cf\u53ef\u80fd\u6ea2\u51fa\uff0c\u6211\u5bf9\u7b2c\u4e8c\u79cd\u65b9\u6848\u7684\u6b63\u786e\u6027\u4ea7\u751f\u4e86\u6000\u7591</p>\n<p>\u7b2c\u4e8c\u79cd\u65b9\u6848\u662f\u5426\u6b63\u786e\uff1f\u5982\u4f55\u9ad8\u6548\u5b9e\u73b0\u8fd9\u4e00\u6bd4\u8f83\u51fd\u6570\uff1f</p>\n<h3>DeepSeek \u56de\u7b54</h3>\n<p>\u5bf9\u4e8e\u7b2c\u4e8c\u79cd\u5b9e\u73b0 <code>qcmp_uint64_2</code>\uff0c\u76f4\u63a5\u8fd4\u56de a - b \u7684\u786e\u5b58\u5728\u9690\u60a3\u3002\u539f\u56e0\u5982\u4e0b\uff1a</p>\n<ol>\n<li>\n<p>\u65e0\u7b26\u53f7\u6574\u6570\u51cf\u6cd5\u4e0d\u4f1a\u6ea2\u51fa\uff0c\u4f46\u7ed3\u679c\u59cb\u7ec8\u4e3a\u975e\u8d1f\u6570\u3002</p>\n<ul>\n<li>\u5f53 a &lt; b \u65f6\uff0ca - b \u4f1a\u5f97\u5230\u4e00\u4e2a\u6781\u5927\u7684\u65e0\u7b26\u53f7\u503c\uff08\u6a21\u8fd0\u7b97\u7ed3\u679c\uff09\uff0c\u4f8b\u5982 1 - 2 = UINT64_MAX \u3002</li>\n</ul>\n</li>\n<li>\n<p>\u8f6c\u6362\u4e3a int \u53ef\u80fd\u5bfc\u81f4\u7b26\u53f7\u9519\u8bef\uff1a</p>\n<ul>\n<li>\u82e5 a - b \u7684\u503c\u8d85\u8fc7 INT_MAX \uff0c\u8f6c\u6362\u4e3a int \u65f6\u4f1a\u89e6\u53d1\u5b9e\u73b0\u5b9a\u4e49\u884c\u4e3a\uff08\u901a\u5e38\u4e3a\u622a\u65ad\u9ad8\u4f4d\uff0c\u5bfc\u81f4\u7ed3\u679c\u4e3a\u8d1f\u6570\uff09\u3002\u6b64\u65f6 qsort \u4f1a\u8bef\u5224 a &lt; b \uff0c\u9020\u6210\u6392\u5e8f\u9519\u8bef\u3002</li>\n</ul>\n</li>\n</ol>\n<p>\u4f8b\u5982\uff1a</p>\n<ul>\n<li>\u82e5 a = 1, b = 2 \uff0c\u5219 a - b = UINT64_MAX \u3002</li>\n<li>\u8f6c\u6362\u4e3a int \u65f6\uff0c\u5047\u8bbe int \u4e3a 32 \u4f4d\uff0c\u7ed3\u679c\u4e3a -1 \uff08\u6b63\u786e\uff09\u3002</li>\n<li>\u4f46\u82e5 a = 0x80000000, b = 0 \uff0c\u5728 32 \u4f4d int \u4e0b\uff0c\u8f6c\u6362\u540e\u4e3a\u8d1f\u6570\uff08\u9519\u8bef\uff09\u3002</li>\n</ul>\n<p>\u9ad8\u6548\u4e14\u5b89\u5168\u7684\u5b9e\u73b0\n\u5229\u7528 \u6bd4\u8f83\u64cd\u4f5c\u7684\u5e03\u5c14\u503c\u9690\u5f0f\u8f6c\u6362\u4e3a 0/1 \uff0c\u53ef\u5199\u51fa\u65e0\u5206\u652f\u7684\u9ad8\u6548\u4ee3\u7801\uff1a</p>\n<pre><code class=\"language-c\">int qcmp_uint64(const void* pa, const void* pb) {\n  uint64_t a = *(const uint64_t*)pa;\n  uint64_t b = *(const uint64_t*)pb;\n  return (a &gt; b) - (a &lt; b);  // \u82e5 a &gt; b \u5219 1-0=1 \uff1b a &lt; b \u5219 0-1=-1 \uff1b\u76f8\u7b49\u5219\u4e3a 0\n}\n</code></pre>\n<p>\u4f18\u70b9\uff1a</p>\n<ul>\n<li>\u5b8c\u5168\u907f\u514d\u6ea2\u51fa\u98ce\u9669\uff1a\u4e0d\u4f9d\u8d56\u6570\u503c\u8fd0\u7b97\uff0c\u4ec5\u7528\u6bd4\u8f83\u7ed3\u679c\u3002</li>\n<li>\u65e0\u5206\u652f\uff1a\u73b0\u4ee3\u7f16\u8bd1\u5668\uff08\u5982 GCC/Clang \uff09\u4f1a\u5c06\u5176\u4f18\u5316\u4e3a\u65e0\u8df3\u8f6c\u6307\u4ee4\uff0c\u6027\u80fd\u4e0e a - b \u76f8\u8fd1\u3002</li>\n<li>\u4ee3\u7801\u7b80\u6d01\uff1a\u7b26\u5408\u4e25\u683c\u6bd4\u8f83\u903b\u8f91\u3002</li>\n</ul>\n<p>\u6027\u80fd\u9a8c\u8bc1</p>\n<p>\u5728 x86-64 \u67b6\u6784\u4e0b\uff0c\u4e0a\u8ff0\u4ee3\u7801\u7684\u5178\u578b\u6c47\u7f16\u8f93\u51fa\u4e3a\uff1a</p>\n<pre><code class=\"language-asm\">mov    rax, [rdi]\ncmp    [rsi], rax\nsetb   al\nseta   cl\nmovzx  eax, al\nmovzx  ecx, cl\nsub    eax, ecx\nret\n</code></pre>\n<p>\u5b8c\u5168\u65e0\u5206\u652f\uff0c\u6548\u7387\u4e0e\u51cf\u6cd5\u65b9\u6848\u76f8\u5f53\uff0c\u4e14\u7edd\u5bf9\u5b89\u5168\u3002</p>\n<p>\u7ed3\u8bba\uff1a\u4e0d\u8981\u4f7f\u7528 a - b \u65b9\u6848\uff0c\u4f18\u5148\u9009\u62e9\u65e0\u5206\u652f\u7684\u5e03\u5c14\u6bd4\u8f83\u5b9e\u73b0\u3002</p>\n<h3>\u70b9\u8bc4</h3>\n<p>\u8fd9\u4e2a (a &gt; b) - (a &lt; b) \u7684\u5199\u6cd5\u592a\u5de7\u5999\u4e86\uff01</p>\n<p>\u611f\u89c9\u8fd9\u7c7b\u60ef\u7528\u6cd5\uff08 idiom \uff09\u5f88\u96be\u901a\u8fc7\u770b\u4e66\u6216\u7f51\u7edc\u5b66\u4e60\uff0c\u6b63\u662f AI \u7684\u5f3a\u9879</p>\n<p>\u53ea\u641c\u5230\u4e00\u4e2a\u76f8\u5173\u7684\uff1a <a href=\"https://stackoverflow.com/questions/3886446/problem-trying-to-use-the-c-qsort-function\" rel=\"nofollow\">https://stackoverflow.com/questions/3886446/problem-trying-to-use-the-c-qsort-function</a></p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/kelvinaltajiin", 
        "name": "kelvinaltajiin", 
        "avatar": "https://cdn.v2ex.com/avatar/8e9e/eb9b/613774_large.png?m=1758068458"
      }, 
      "url": "https://www.v2ex.com/t/1125556", 
      "title": "\u4e00\u4e2a\u7b80\u5355\u7684 C \u7a0b\u5e8f\uff0c\u4f46\u662f\u4e0d\u660e\u767d\u533a\u522b\u5728\u54ea\u91cc", 
      "id": "https://www.v2ex.com/t/1125556", 
      "date_published": "2025-04-15T03:49:31+00:00", 
      "content_html": "<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\nvoid assign_value(int *array, int index, int value);\nint main() {\n  printf(\"Hello, World!\\n\");\n  int array[10];\n  assign_value(array, 16, 131);\n  printf(\"%d\\n\", array[16]);\n  return 0;\n}\n\nvoid assign_value(int *array, int index, int value) {\n  array[index] = value;\n  printf(\"done\\n\");\n}\n\n</code></pre>\n<p>\u7f16\u8bd1\uff1a$ gcc -g -Wall -std=c18 -o hello_world hello_world.c\n\u8fd0\u884c\u8f93\u51fa\uff1a</p>\n<pre><code class=\"language-shell\">Hello, World!\ndone\n131\n[1]    3719 segmentation fault (core dumped)  ./hello_world\n</code></pre>\n<p>\u4f46\u662f\u5982\u679c\u628a index \u4ece 16 \u6539\u6210 12, \u5219\u4e0d\u4f1a\u51fa\u73b0\u6700\u540e\u7684 segmentation fault. \u5982\u679c C \u4e0d\u5904\u7406\u8d8a\u754c\u7684\u8bdd\uff0c\u4e3a\u4ec0\u4e48 16 \u4f1a\u62a5\u9519\uff0c\u5982\u679c\u5904\u7406\u8d8a\u754c\u4e3a\u4ec0\u4e48 12 \u4e0d\u62a5\u9519\uff1f</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/Exxfire", 
        "name": "Exxfire", 
        "avatar": "https://cdn.v2ex.com/gravatar/d0c05e7c27c838082240f375e003f5ec?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1111103", 
      "date_modified": "2025-02-13T04:52:51+00:00", 
      "content_html": "<pre><code>#include &lt;stdio.h&gt;\n\nstruct X\n{\n    int a;\n    char c[10];\n    short d;\n};\nchar checker(int a)\n{\n    (void)a;\n    return '1';\n}\n\n#define STRINGIFY(x) #x\n#define TOSTRING(x) STRINGIFY(x)\n\n#define TEST(x)                                                              \\\n    do                                                                       \\\n    {                                                                        \\\n        char checkSizeOfInt[sizeof(x)] = {checker(&amp;checkSizeOfInt)};         \\\n        _Pragma(TOSTRING(message(\"Value: \" #x)))                             \\\n    } while (0);\n\nint main() {\n    TEST(struct X);\n    return 0;\n}\n</code></pre>\n", 
      "date_published": "2025-02-13T02:25:49+00:00", 
      "title": "\u6211\u8fd9\u6bb5 C \u4ee3\u7801\u53ef\u4ee5\u5728\u7f16\u8bd1\u65f6\u5019\u8f93\u51fa\u7ed3\u6784\u4f53\u7684\u5927\u5c0f\uff0c\u4f60\u4eec\u8fd8\u6709\u4ec0\u4e48\u597d\u70b9\u5b50\uff0c show me the code!", 
      "id": "https://www.v2ex.com/t/1111103"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/cnbatch", 
        "name": "cnbatch", 
        "avatar": "https://cdn.v2ex.com/gravatar/7eb06cdf719fb364a1dfbbaefc4f9d36?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1093235", 
      "title": "\u8fd9\u6bb5\u8bdd\u662f\u5426\u6b63\u786e\uff1f\u300c\u53d6\u4f59\u8fd9\u4e2a\u8fd0\u7b97\uff0c\u53ea\u6709 Python \u662f\u5bf9\u7684\u3002\u5f53\u521d C \u8fd9\u4e2a\u8001\u5e08\u6559\u9519\u4e86\uff0c\u90a3\u4e48\u4e00\u5927\u7968\u5b66\u751f\u4e5f\u5c31\u53ea\u6562\u8ddf\u7740\u8001\u5e08\u9519\u3002\u53ea\u6709 Python \u6562\u4e8e\u7ad9\u51fa\u6765\u575a\u6301\u6b63\u786e\u7b54\u6848\u3002\u300d", 
      "id": "https://www.v2ex.com/t/1093235", 
      "date_published": "2024-11-27T15:50:46+00:00", 
      "content_html": "<p>\u4eca\u5929\u5728\u770b\u4e00\u7bc7\u516c\u4f17\u53f7\u6587\u7ae0\u300a<a href=\"https://mp.weixin.qq.com/s/hpFshExbXV9_nm-CdSoM_w\" rel=\"nofollow\">\u6027\u80fd\u4e4b\u738b\uff1a\u6700\u5feb\u7684\u7f16\u7a0b\u8bed\u8a00</a>\u300b\uff0c\u53d1\u73b0\u8bc4\u8bba\u533a\u6709\u8fd9\u4e48\u4e00\u6bb5\u5bf9\u8bdd\uff1a</p>\n<p><img alt=\"img\" class=\"embedded_image\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"https://i.imgur.com/alrefau.jpeg\"/></p>\n<p><img alt=\"img2\" class=\"embedded_image\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"https://i.imgur.com/be6AVPg.jpeg\"/></p>\n<p>\u7136\u540e\u6211\u627e\u4e86\u4e0b\u5728 stackexchange \u7684\u771f\u5b9e\u63d0\u95ee\uff1a</p>\n<p><a href=\"https://math.stackexchange.com/questions/623449/negative-number-divided-by-positive-number-what-would-be-remainder\" rel=\"nofollow\">https://math.stackexchange.com/questions/623449/negative-number-divided-by-positive-number-what-would-be-remainder</a></p>\n<p>\u4ece\u56de\u7b54\u6765\u770b\uff0cC \u548c Python \u7684\u4e24\u79cd\u505a\u6cd5\u5728\u6570\u503c\u8ba1\u7b97\u4e0a\u90fd\u662f\u6210\u7acb\u7684\u3002\u4e24\u79cd\u505a\u6cd5\u7684<strong>\u533a\u522b\u5728\u4e8e\u662f\u5426\u5141\u8bb8\u4f59\u6570\u4e3a\u8d1f\u6570</strong>\uff0c\u6216\u8005\u8bf4\uff0c\u7b26\u53f7\u8be5\u4e0d\u8be5\u4e0e\u539f\u6570\u503c\u76f8\u540c\u3002</p>\n<p>\u4e0d\u5141\u8bb8\u4f59\u6570\u51fa\u73b0\u8d1f\u6570\u7684\uff0c\u662f\u76ee\u524d\u5e7f\u6cdb\u4f7f\u7528\u7684\u6b27\u51e0\u91cc\u5f97\u9664\u6cd5\u3002</p>\n<p>\u6240\u4ee5\u201c\u6570\u5b66\u6d01\u7656\u201d\u4f1a\u8ba4\u4e3a\u8d1f\u503c\u4f59\u6570\u662f\u9519\u7684\uff1f</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/XIVN1987", 
        "name": "XIVN1987", 
        "avatar": "https://cdn.v2ex.com/avatar/c4ce/3bc8/138148_large.png?m=1772508180"
      }, 
      "url": "https://www.v2ex.com/t/1088956", 
      "title": "C \u4e2d\u53ef\u53d8\u53c2\u6570\u5982\u4f55\u76f4\u63a5\u4f20\u9012\u5230 printf()", 
      "id": "https://www.v2ex.com/t/1088956", 
      "date_published": "2024-11-12T09:41:03+00:00", 
      "content_html": "<p>\u7528\u5230\u4e00\u4e2a\u5e93\uff0c\uff0c\u5b83\u6709\u4e00\u4e2a\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a</p>\n<pre><code class=\"language-C\">/**\n * @brief     interface print format data\n * @param[in] fmt is the format data\n * @note      none\n */\nvoid ov2640_interface_debug_print(const char *const fmt, ...)\n{\n}\n</code></pre>\n<p>\u8fd9\u4e2a\u51fd\u6570\u7684\u51fd\u6570\u539f\u578b\u4e0e printf \u5b8c\u5168\u4e00\u81f4\uff0c\uff0c\u6240\u4ee5\u6211\u60f3\u50cf\u4e0b\u9762\u8fd9\u6837\u76f4\u63a5\u628a\u5b83\u7684\u53c2\u6570\u4f20\u9012\u7ed9 printf \uff0c\uff0c\u53ef\u662f\u7f16\u8bd1\u5668\u62a5\u9519\uff0c\uff0c\u8bf7\u95ee\u5e94\u8be5\u600e\u4e48\u6539\uff1f\uff1f</p>\n<pre><code class=\"language-C\">void ov2640_interface_debug_print(const char *const fmt, ...)\n{\n\tprintf(fmt, ...);\n}\n</code></pre>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/BlackSnow", 
        "name": "BlackSnow", 
        "avatar": "https://cdn.v2ex.com/avatar/077f/9542/682408_large.png?m=1724034304"
      }, 
      "url": "https://www.v2ex.com/t/1069103", 
      "title": "C \u7684\u5185\u5b58\u6253\u5370\u5b9e\u73b0", 
      "id": "https://www.v2ex.com/t/1069103", 
      "date_published": "2024-08-30T09:27:37+00:00", 
      "content_html": "<p>\u8bf7\u6559\u4e00\u4e2a\u57fa\u7840\u95ee\u9898\uff0c\u5b9e\u9645\u6267\u884c\u7684\u4ee3\u7801\u65f6\u662f\u653e\u5165\u4e86\u865a\u62df\u5185\u5b58\u4e2d\uff0c\u8fd9\u4e2a\u5185\u5b58\u7684\u683c\u5f0f\u4e0e\u7269\u7406\u5185\u5b58\u4e00\u81f4\u5417\uff0c\u8fd8\u662f\u6bcf\u4e2a\u5185\u5b58\u5355\u5143\u5360\u4e00\u5b57\u8282\n\u5982\u679c\u662f\u7684\u8bdd\uff0c\u90a3\u4e48\u4e0b\u9762\u4e24\u4e2a\u95ee\u9898\u80fd\u4e0d\u80fd\u76f4\u89c2\u53cd\u6620</p>\n<ol>\n<li>C \u8bed\u8a00\u652f\u6301\u5177\u4f53\u7684\u865a\u62df\u5185\u5b58\u6253\u5370\u5417\n\u6bd4\u5982 \u6211\u662f\u5426\u53ef\u4ee5\u4f7f\u7528\u67d0\u79cd\u51fd\u6570\u4e0b\u9762\u7684 1001 \u7684\u5177\u4f53\u5185\u5b58\u503c\uff0c\u60f3\u9a8c\u8bc1\u4e00\u4e0b f3 0f 1e fa \u662f\u4ece\u5bc4\u5b58\u5668\u653e\u5165\u4e86 4 \u4e2a\u5185\u5b58\u5730\u5740\u8fd8\u662f\u8bf4\u53ea\u662f\u7528\u4e86 1000 \u7684\u5730\u5740\n\u5982\u4e0b\u4ee3\u7801</li>\n</ol>\n<pre><code>    1000:\tf3 0f 1e fa          \tendbr64\n    1004:\t48 83 ec 08          \tsub    $0x8,%rsp\n    1008:\t48 8b 05 d9 2f 00 00 \tmov    0x2fd9(%rip),%rax        # 3fe8 &lt;__gmon_start__@Base&gt;\n    100f:\t48 85 c0             \ttest   %rax,%rax\n    1012:\t74 02                \tje     1016 &lt;_init+0x16&gt;\n\n</code></pre>\n<ol>\n<li>\u5982\u679c\u9a8c\u8bc1\u6b63\u786e\u7684\u8bdd\uff0c\u8fd9\u91cc\u7684\u5185\u5b58\u662f\u64cd\u4f5c\u7cfb\u7edf\u7cfb\u7edf\u6a21\u62df\u7684\uff0c\u56e0\u6b64\u5185\u5b58\u5355\u5143\u957f\u5ea6\u56fa\u5b9a\u662f 1 \u5b57\u8282\u5bf9\u5417</li>\n</ol>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/smdbh", 
        "name": "smdbh", 
        "avatar": "https://cdn.v2ex.com/gravatar/98d0f8f3a8989d099a133b2fb2570323?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1068118", 
      "title": "\u51fd\u6570\u80fd\u5426\u5b9e\u73b0\u900f\u4f20\u4e0d\u5b9a\u957f\u5ea6\u53c2\u6570\uff0c\u6700\u7ec8\u7531 printf \u6253\u5370", 
      "id": "https://www.v2ex.com/t/1068118", 
      "date_published": "2024-08-27T05:15:23+00:00", 
      "content_html": "<p>\u6bd4\u5982\u8981\u5c01\u88c5\u4e00\u4e2a\u6253\u5370\u51fd\u6570,\u6253\u5370\u5185\u5bb9\u5728\u6700\u540e\uff0c\u5165\u53e3\u65f6 myprint1 \uff0c\u540e\u7eed\u65f6 myprint2 \uff0c\u3002\u3002\u3002\uff0c\u53c2\u6570\u8981\u5982\u4f55\u5199\uff1f</p>\n<pre><code>void myprint1(uint8_t *pdata, size_t len, char *fmt, ...)\n{\n\tmyprint2(fmt,...);\t\t// \u8fd9\u91cc\u53c2\u6570\u600e\u4e48\u5199\n}\n\nvoid mprint2(char *fmt, ...)\n{\n\tprintf(fmt,...);\t\t// \u5982\u4f55\u8c03\u7528\n}\n\n</code></pre>\n<p>\u8c22\u8c22</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/cjd6568358", 
        "name": "cjd6568358", 
        "avatar": "https://cdn.v2ex.com/gravatar/763b25e27dc0a5a52f5e81893a0ae438?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1065314", 
      "title": "\u8bf7\u5927\u4f6c\u5e2e\u5fd9\u4fee\u6539\u4e00\u4efd elf \u6587\u4ef6\u91cc\u7684\u6570\u503c", 
      "id": "https://www.v2ex.com/t/1065314", 
      "date_published": "2024-08-15T11:41:10+00:00", 
      "content_html": "\u5bb6\u91cc\u6709\u4e00\u53f0\u5c0f\u8681\u6444\u50cf\u673a\uff0c\u7834\u89e3\u540e\u4f7f\u7528 cifs \u6302\u8f7d\u4e86\u4e00\u4efd\u7f51\u7edc\u4e91\u76d8\uff0c\u8fd9\u6837\u7684\u8bdd\u5c31\u53ef\u4ee5\u76f4\u63a5\u628a\u89c6\u9891\u5f55\u5236\u5230\u4e91\u76d8\u91cc\uff0c\u4e0d\u9700\u8981\u7ecf\u8fc7 sd \u5361\u4e2d\u8f6c\u3002\u73b0\u5728\u9047\u5230\u4e86\u4e00\u4e2a\u95ee\u9898\u5c31\u662f\u539f\u7248\u56fa\u4ef6\u9650\u5236\u4e86 sd \u5361\u7684\u5927\u5c0f\uff0c\u5c0f\u4e8e 3072mb \u7684\u5185\u5b58\u5361\u4f1a\u76f4\u63a5\u65e0\u6cd5\u5f55\u5236\u89c6\u9891\u3002\u60f3\u8981\u628a\u6570\u503c\u4fee\u6539\u4e3a 256.<br />\u6587\u4ef6\u94fe\u63a5<br /><br /><a target=\"_blank\" href=\"https://wwdm.lanzouo.com/iiUCY27i6vsd\" rel=\"nofollow noopener\">https://wwdm.lanzouo.com/iiUCY27i6vsd</a>"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/SS945", 
        "name": "SS945", 
        "avatar": "https://cdn.v2ex.com/gravatar/df7174a1aebd8f471697111d89d52b74?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1062935", 
      "date_modified": "2024-08-06T07:12:27+00:00", 
      "content_html": "#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;unistd.h&gt;<br />#include &lt;errno.h&gt;<br />#include &lt;sys/types.h&gt;<br />#include &lt;sys/wait.h&gt;<br />#include &lt;signal.h&gt;<br />#include &lt;sys/prctl.h&gt;<br />#include &lt;string.h&gt;<br />#include &lt;pthread.h&gt;<br />#include &lt;liblx_api/lx_api.h&gt;<br /><br /><br />static void *client_check(void *arg)<br />{<br />    printf(\"###### %s %d ######\\n\", __FUNCTION__, __LINE__);<br />    #define SZ_BUF 32768 /* 32*1024 */<br />    char post_data[SZ_BUF] = {0};<br />    char enc_msg[SZ_BUF + 16] = {0};<br />    unsigned char cipher_data[SZ_BUF] = {0};<br />    unsigned char cipher_str[SZ_BUF] = {0};<br />    unsigned char test[SZ_BUF] = {0};<br />    strcpy((char *)cipher_data, \"AAAAAAAAAAAAAAAAA\");<br />    strcpy((char *)cipher_str, \"CCCCCCCCCCCCCCC\");<br />    strcpy((char *)enc_msg, \"DDDDDDDDDDDDDDDD\");<br />    strcpy((char *)post_data, \"EEEEEEEEEEEEEEE\");<br />    strcpy((char *)test, \"FFFFFFFFFFFFFFFFF\");<br />    printf(\"###### %s %d ######\\n\", __FUNCTION__, __LINE__);<br /><br />    return 0;<br />}<br /><br /><br />int main(void)<br />{<br />    pthread_t tidp;<br />    printf(\"\\n######## start #####\\n\");<br />    test_service();  //\u5de5\u4f5c\u6b63\u5e38<br />    if (pthread_create(&amp;tidp, NULL, client_check, NULL) != 0)  //\u5f02\u5e38\u9000\u51fa <br />    {<br />        LX_NGX_ERR(\"pthread_create error!\\n\");<br />    }<br /><br />    printf(\"AAAAAAA hello world!!!\\n\");    <br />    return 0;<br />}<br /><br /><br />\u4e0a\u9762\u7684\u7a0b\u5e8f\u5982\u679c\u6b63\u5e38\u5728 main \u91cc\u9762\u8dd1\u5c31\u662f\u597d\u7684\uff0c\u4f46\u4e00\u653e\u5230 pthread_create \u91cc\u9762\u7528\u7ebf\u7a0b\u8dd1\u5c31\u4e0d\u884c\uff0c\u653e\u5728 x86 \u4e0a\u5c31\u53ef\u4ee5\uff0c\u4f46\u653e\u5728\u6211\u7684\u677f\u5b50\u91cc\u677f\u5c31\u4e0d\u884c\uff0c\u8fd9\u662f\u4ec0\u4e48\u9b3c\uff1f\uff1f\uff1f\uff1f", 
      "date_published": "2024-08-06T06:39:25+00:00", 
      "title": "Linux \u4e0a C \u7684\u7a0b\u5e8f\u9047\u5230\u4e2a\u5f02\u5e38\u9000\u51fa\u95ee\u9898\uff0c\u5c40\u90e8\u53d8\u91cf\u5927\u5c0f\u6709\u9650\u5236\uff1f\uff1f", 
      "id": "https://www.v2ex.com/t/1062935"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/craiiz", 
        "name": "craiiz", 
        "avatar": "https://cdn.v2ex.com/avatar/4cd7/d2bf/176744_large.png?m=1750316160"
      }, 
      "url": "https://www.v2ex.com/t/1055651", 
      "title": "C \u8bed\u8a00\u65b0\u624b\u6c42\u52a9\uff1a\u5982\u4f55\u5728 vscode \u4e2d\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff1f", 
      "id": "https://www.v2ex.com/t/1055651", 
      "date_published": "2024-07-08T06:18:43+00:00", 
      "content_html": "<blockquote>\n<p>\u80cc\u666f\u662f\u8fd9\u6837\u7684\uff1a\u6700\u8fd1\u95f2\u7740\u62a5\u4e86\u4e2a\u6df1\u5733\u4eba\u793e\u7684 c \u8bed\u8a00\u57f9\u8bad\u73ed\u3002 \u5b8c\u4e86\u4e4b\u540e\u60f3\u8981\u628a\u4e4b\u524d\u81ea\u5df1\u5199\u7684 python \u56fe\u7247\u5904\u7406\u811a\u672c\u7528 C \u5199\u4e00\u904d\u3002 \u7136\u540e\u5c31\u53d1\u73b0\u6ca1\u6cd5\u5f15\u7528\u7b2c\u4e09\u65b9\u5e93(\u4e5f\u8bb8\u662f\u81ea\u5df1\u54ea\u91cc\u505a\u9519\u4e86)\u3002</p>\n</blockquote>\n<h2>\u60f3\u8981\u8fbe\u6210\u7684\u76ee\u7684</h2>\n<ol>\n<li>\u5728 vscode \u4e2d\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff1b</li>\n<li>\u4e86\u89e3\u6211\u7684 .vscode \u91cc\u9762\u7684\u914d\u7f6e\u6587\u4ef6\u662f\u4e0d\u662f\u54ea\u91cc\u5199\u9519\u4e86\uff1f</li>\n</ol>\n<h2>\u5f53\u524d\u60c5\u51b5\u53ca\u65e0\u6cd5\u89e3\u51b3\u7684\u95ee\u9898(\u5df2 google \u548c gpt)</h2>\n<p>\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93 <strong>fmt</strong> \u4e3a\u4f8b\uff0c\u6309\u7167\u4e0b\u8ff0\u64cd\u4f5c\u4e4b\u540e\uff0c\u5728\u6d4b\u8bd5\u6587\u4ef6 <code> test.c</code>  \u91cc\u9762\u8f93\u5165 <code> #include &lt;f</code>  vscode \u80fd\u81ea\u52a8\u8054\u60f3\u51fa<code>#include &lt;fmt/format.h&gt; </code> \uff0c\u4f46\u662f\u5728 debug \u6216 run without debug \u65f6\u7ec8\u7aef\u4f1a\u62a5\u9519\u4ee5\u4e0b\u5185\u5bb9 \uff1a</p>\n<p>#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\\Users\\xxx\\Desktop\\C\\test.c).</p>\n<p>cannot open source file \"cmath\" (dependency of \"C:\\Users\\xxx.vscode\\extensions\\ms-vscode.cpptools-1.20.5-win32-x64\\bin\\fmt\\format.h\"). Please run the 'Select IntelliSense Configuration...' command to locate your system headers.</p>\n<p>fmt/format.h: No such file or directory</p>\n<h2>\u5df2\u7ecf\u8fdb\u884c\u7684\u64cd\u4f5c</h2>\n<ol>\n<li>\n<p>gcc/gdb \u90fd\u5df2\u7ecf\u6b63\u5e38\u5b89\u88c5\u5e76\u4e14\u53ef\u4ee5\u5728\u7ec8\u7aef\u6b63\u5e38\u4f7f\u7528\uff1b\n\u5176\u4e2d\uff0cgcc \u8def\u5f84\u4e3a\uff1aC:\\MinGW\\bin\\gcc.exe ; gdb \u7248\u672c\u4e3a GNU gdb (GDB) 7.6.1 \uff1b</p>\n</li>\n<li>\n<p>\u5305\u7ba1\u7406\u7528\u7684\u662f vcpkg;\n\u5b89\u88c5\u5230\u5305\u7684\u8def\u5f84\u662f\uff1aC:\\vcpkg\\installed\\x64-windows\\include</p>\n</li>\n<li>\n<p>vscode \u88c5\u4e86\u63d2\u4ef6\uff1aC/C++ v1.20.5</p>\n</li>\n<li>\n<p>\u5728 google \u64cd\u4f5c\u4e4b\u540e\u4e0b\u6765\uff0c\u4e4b\u540e\u76f8\u5173\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a</p>\n</li>\n</ol>\n<p><strong>c_cpp_properties.json\uff1a</strong></p>\n<pre><code>{\n    \"configurations\": [\n        {\n            \"name\": \"Win32\",\n            \"includePath\": [\n                \"${workspaceFolder}/**\",\n                \"C:/vcpkg/installed/x64-windows/include\",\n                \"C:/MinGW/include\"\n            ],\n            \"defines\": [],\n            \"windowsSdkVersion\": \"10.0.18362.0\",\n            \"cStandard\": \"c11\",\n            \"cppStandard\": \"c++17\",\n            \"intelliSenseMode\": \"windows-gcc-x64\"\n        }\n    ],\n    \"version\": 4\n}\n\n</code></pre>\n<p><strong>tasks.json\uff1a</strong></p>\n<pre><code>{\n    \"version\": \"2.0.0\",\n    \"tasks\": [\n        {\n            \"type\": \"shell\",\n            \"label\": \"gcc build active file\",\n            \"command\": \"gcc\",\n            \"args\": [\n                \"-g\",\n                \"${file}\",\n                \"-I\",\n                \"C:/vcpkg/installed/x64-windows/include\",\n                \"-L\",\n                \"C:/vcpkg/installed/x64-windows/lib\",\n                \"-lfmt\",\n                \"-o\",\n                \"${fileDirname}/${fileBasenameNoExtension}.exe\"\n            ],\n            \"group\": \"build\"\n        },\n        {\n            \"type\": \"cppbuild\",\n            \"label\": \"C/C++: gcc.exe build active file\",\n            \"command\": \"C:\\\\MinGW\\\\bin\\\\gcc.exe\",\n            \"args\": [\n                \"-fdiagnostics-color=always\",\n                \"-g\",\n                \"${file}\",\n                \"-o\",\n                \"${fileDirname}\\\\${fileBasenameNoExtension}.exe\"\n            ],\n            \"options\": {\n                \"cwd\": \"${fileDirname}\"\n            },\n            \"problemMatcher\": [\n                \"$gcc\"\n            ],\n            \"group\": {\n                \"kind\": \"build\",\n                \"isDefault\": true\n            },\n            \"detail\": \"Task generated by Debugger.\"\n        }\n    ]\n}\n\n</code></pre>\n<p><strong>launch.json\uff1a</strong></p>\n<pre><code>{\n    // Use IntelliSense to learn about possible attributes.\n    // Hover to view descriptions of existing attributes.\n    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n    \"version\": \"0.2.0\",\n    \"configurations\": [\n        {\n            \"name\": \"(gdb) Attach\",\n            \"type\": \"cppdbg\",\n            \"request\": \"attach\",\n            \"program\": \"${workspaceRoot}/${fileBasenameNoExtension}.exe\",\n            \"MIMode\": \"gdb\",\n            \"miDebuggerPath\": \"gdb\",\n            \"setupCommands\": [\n                {\n                    \"description\": \"Enable pretty-printing for gdb\",\n                    \"text\": \"-enable-pretty-printing\",\n                    \"ignoreFailures\": true\n                },\n                {\n                    \"description\": \"Set Disassembly Flavor to Intel\",\n                    \"text\": \"-gdb-set disassembly-flavor intel\",\n                    \"ignoreFailures\": true\n                }\n            ]\n        }\n\n    ]\n}\n\n</code></pre>\n<p><strong>\u6d4b\u8bd5\u811a\u672c</strong></p>\n<pre><code>#include &lt;fmt/format.h&gt;\n\nint main(void){\n\n    int a = 1;\n    fmt::print(\"a is {}\", a);\n    \n    return 0;\n}\n\n</code></pre>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/zhng920823", 
        "name": "zhng920823", 
        "avatar": "https://cdn.v2ex.com/avatar/5f48/c7c2/429679_large.png?m=1742114392"
      }, 
      "url": "https://www.v2ex.com/t/1055626", 
      "date_modified": "2024-07-08T04:41:59+00:00", 
      "content_html": "<p>\u4fdd\u6301\u76ee\u5f55\u7ed3\u6784\u53ef\u4ee5\u65b9\u4fbf\u6839\u636e\u8def\u5f84\u67e5\u627e\u4f7f\u7528.</p>\n<ul>\n<li>bash \u811a\u672c\u7528\u6765\u751f\u6210 .c \u6587\u4ef6</li>\n</ul>\n<pre><code>chmod +x embed_file_c.sh\n\n./embed_file_c.sh dir2c_test\n# or\n./embed_file_c.sh dir2c /path/to/resource &gt; _data_enc.c\ngcc embed_file.c -o embed_file\n./embed_file\n</code></pre>\n<ul>\n<li>\u751f\u6210\u7684 .c \u6587\u4ef6\u8fd9\u6837\u4f7f\u7528</li>\n</ul>\n<pre><code>#include &lt;stdio.h&gt;\n#include &lt;stdint.h&gt;\nint main(int argc, char *argv[]) {\n\t#define _DATA_ENC_INC 1\n\t#include \"_data_enc.c\"\n\tfor (int i = 0; i &lt; sizeof(_data_enc_lst)/sizeof(_data_enc_lst[0]); ++i) {\n\t\tprintf(\"%3u, %3u, %s\\n\", _data_enc_lst[i].off, _data_enc_lst[i].len, _data_enc_lst[i].path);\n\t\t// &amp;_data_enc[_data_enc_lst[i].off] is the data ptr, use it by need\n\t}\n\treturn 0;\n}\n</code></pre>\n<p>\u4ee3\u7801 <a href=\"https://github.com/webd90kb/webd/tree/master/codes/scripts/embed_file_c\" rel=\"nofollow\">https://github.com/webd90kb/webd/tree/master/codes/scripts/embed_file_c</a></p>\n", 
      "date_published": "2024-07-08T04:40:18+00:00", 
      "title": "\u5c06\u8d44\u6e90\u5d4c\u5165\u5230\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u5e76\u4fdd\u6301\u76ee\u5f55\u7ed3\u6784", 
      "id": "https://www.v2ex.com/t/1055626"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/zhng920823", 
        "name": "zhng920823", 
        "avatar": "https://cdn.v2ex.com/avatar/5f48/c7c2/429679_large.png?m=1742114392"
      }, 
      "url": "https://www.v2ex.com/t/1055621", 
      "title": "\u4e00\u4e2a\u7b80\u5355\u5b9e\u7528\u7684 C \u5de5\u7a0b\u793a\u4f8b, \u9644\u7b80\u6d01\u7684 Makefile", 
      "id": "https://www.v2ex.com/t/1055621", 
      "date_published": "2024-07-08T04:06:48+00:00", 
      "content_html": "<p>Makefile \u53ef\u4ee5\u505a\u5230\u5982\u4e0b\u7b80\u6d01, \u5b9e\u9645\u7528\u65f6\u53ea\u8981\u4fee\u6539 EXE \u548c OBJ \u7684\u5217\u8868\u503c, \u65e0\u9700\u5173\u5fc3\u5176\u5b83\u7684\u4e1c\u897f</p>\n<pre><code>EXE=\\\nexe1\\\na/exe2\\\na/exe3\\\n\nOBJ=\\\nmod1\\\nliba/mod2\\\nliba/mod3\\\n\ninclude inc.mak\n</code></pre>\n<p>\u5de5\u7a0b\u6e90\u7801 <a href=\"https://github.com/webd90kb/webd/tree/master/codes/c_project_template\" rel=\"nofollow\">https://github.com/webd90kb/webd/tree/master/codes/c_project_template</a></p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/Canglin", 
        "name": "Canglin", 
        "avatar": "https://cdn.v2ex.com/avatar/9131/cc11/671959_large.png?m=1733713671"
      }, 
      "url": "https://www.v2ex.com/t/1046163", 
      "date_modified": "2024-06-02T15:02:03+00:00", 
      "content_html": "\u6211\u662f\u4e00\u4e2a\u521d\u5b66\u8005\uff0c\u76ee\u524d\u5df2\u7ecf\u770b\u5b8c\u4e86 C primer plus \uff0c\u4f46\u662f\u611f\u89c9\u4ec0\u4e48\u90fd\u505a\u4e0d\u4e86\uff0c\u60f3\u95ee\u95ee\u670b\u53cb\u4eec\u60f3\u5b66\u4e60 C \u7684\u7f51\u7edc\u3001\u591a\u7ebf\u7a0b\u3001\u6570\u636e\u5e93\u3001GUI \u76f8\u5173\u5185\u5bb9\u5e94\u8be5\u770b\u70b9\u4ec0\u4e48\u4e66", 
      "date_published": "2024-06-02T13:20:27+00:00", 
      "title": "\u5173\u4e8e C \u8bed\u8a00\u7684\u76f8\u5173\u95ee\u9898", 
      "id": "https://www.v2ex.com/t/1046163"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/Neur2n", 
        "name": "Neur2n", 
        "avatar": "https://cdn.v2ex.com/avatar/7b84/1572/372550_large.png?m=1717036072"
      }, 
      "url": "https://www.v2ex.com/t/1045670", 
      "date_modified": "2024-05-31T05:26:59+00:00", 
      "content_html": "<p>\u5fd8\u8bb0\u4e0a\u94fe\u63a5\u4e86\uff1a<a href=\"https://github.com/neur1n/x.h\" rel=\"nofollow\">https://github.com/neur1n/x.h</a></p>\n<p>\u4e00\u4e07\u5e74\u524d\u5199\u4e86\u4e2a<a href=\"https://v2ex.com/t/919892\" rel=\"nofollow\">C \u8bed\u8a00\u8de8\u5e73\u53f0\u5c0f\u5de5\u5177\u5e93</a>\uff0c\u63d0\u5230\u4e00\u5f00\u59cb\u662f\u7528 C++\u5199\u7684\uff0c\u540e\u6765\u6539\u6210\u4e86 C99 \u3002\u7ed3\u679c\u73b0\u5728\u53c8\u641e\u4e86\u4e00\u4e2a C++\u7248\u672c\uff08 C \u7248\u672c\u8fd8\u4fdd\u7559\u4e14\u4e24\u4e2a\u7248\u672c\u540c\u6b65\uff09\u3002\u4ee3\u7801\u66f4\u65b0\u4e86\u4e0d\u5c11\uff0c\u4e5f\u91cd\u65b0\u7ec4\u7ec7\u4e86\uff0c\u6587\u6863\u4ece README \u6539\u6210\u4e86 doxygen \uff08\u4f46\u662f\u4e0d\u77e5\u9053\u8981\u600e\u4e48\u5bfc\u5165 github wiki \uff09\u3002\u4e3b\u8981\u529f\u80fd\u6709\uff1a</p>\n<ul>\n<li>\n\u5b8f<ul>\n<li>Feature Configuration</li>\n<li>Architecture Detection</li>\n<li>Compiler Detection</li>\n<li>Operating System Detection</li>\n<li>Platform Detection</li>\n</ul>\n</li>\n<li>Communication\uff1a\u76ee\u524d\u4ec5\u6709 socket</li>\n<li>Console IO\uff1a\u865a\u62df\u6309\u952e\u76f8\u5173</li>\n<li>Date and Time\uff1a\u8ba1\u65f6\uff0c\u65f6\u95f4\u6233\u7b49</li>\n<li>Error Handling\uff1a\u517c\u5bb9\u591a\u79cd\u9519\u8bef\u7801\u7cfb\u7edf\u7684\u4e00\u4e2a\u9519\u8bef\u7801\u7cfb\u7edf</li>\n<li>File System\uff1a\u6587\u4ef6\u7edd\u5bf9\u8def\u5f84\uff0c\u6587\u4ef6\u5927\u5c0f\u7b49</li>\n<li>Hardware\uff1aCPU \u3001GPU \u76f8\u5173\uff08\u76ee\u524d\u529f\u80fd\u975e\u5e38\u5c11\uff09</li>\n<li>Mathematics\uff1a\u8fd9\u4e2a\u5176\u5b9e\u6bd4\u8f83\u6742\uff0c\u7b97\u6570\u76f8\u5173\u7684\u90fd\u653e\u8fdb\u53bb\u4e86</li>\n<li>Memory Management\uff1a\u7a0d\u5fae\u5c01\u88c5\u4e14\u5e26\u9519\u8bef\u63d0\u793a\u7684 malloc \u3001free \u3001memcpy \u7b49</li>\n<li>Standard IO\uff1a\u76ee\u524d\u53ea\u6709\u65e5\u5fd7\u6253\u5370</li>\n<li>String\uff1a\u5b57\u7b26\u4e32\u590d\u5236\u3001\u662f\u5426\u4e3a\u7a7a\u7b49</li>\n</ul>\n<p>\u5176\u5b9e\u662f\u4e00\u4e2a\u5f88\u4e2a\u4eba\u7684\u5de5\u5177\u5e93\uff0c\u5e73\u65f6\u5de5\u4f5c\u7528\u5230\u4ec0\u4e48\u5c31\u52a0\u4ec0\u4e48\u8fdb\u53bb\u3002\u8fd1\u671f\u5728\u73a9 cuda \uff0c\u6240\u4ee5\u4e5f\u52a0\u4e86\u70b9 cuda \u7684\u4e1c\u897f\u3002</p>\n", 
      "date_published": "2024-05-31T05:24:48+00:00", 
      "title": "\u8f6e\u5b50\u66f4\u65b0\uff1a C/C++ \u8de8\u5e73\u53f0\u5c0f\u5de5\u5177\u5e93", 
      "id": "https://www.v2ex.com/t/1045670"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/rookiemaster", 
        "name": "rookiemaster", 
        "avatar": "https://cdn.v2ex.com/avatar/b368/6614/659911_large.png?m=1769416716"
      }, 
      "url": "https://www.v2ex.com/t/1034018", 
      "title": "\u4e3a\u4ec0\u4e48\u4e0b\u5217\u7a0b\u5e8f\u8fdb\u884c\u7684\u662f\u65e0\u7b26\u53f7\u4e58\u6cd5\uff1f", 
      "id": "https://www.v2ex.com/t/1034018", 
      "date_published": "2024-04-19T09:55:09+00:00", 
      "content_html": "<pre><code class=\"language-c\">unsigned int x1 = 0xaeb1c2aa;\nunsigned int x2 = 0xaeb1c2aa;\n\nlong long r_whole = (signed long long)x1 * (signed long long)x2;\n\nprintf(\"r_whole = %lld\\n\",r_whole);\n</code></pre>\n<p>\u8f93\u51fa\u7684\u7ed3\u679c\u662f\u65e0\u7b26\u53f7\u4e58\u6cd5\u7684\u7ed3\u679c\uff1a</p>\n<pre><code>r_whole = 8590088583138384100\n</code></pre>\n<p>\u800c\u4e0b\u9762\u7684\u7a0b\u5e8f</p>\n<pre><code>unsigned int x1 = 0xaeb1c2aa;\nunsigned int x2 = 0xaeb1c2aa;\n\nint xx1 = x1;\nint xx2 = x2;\n\nlong long r_whole = (signed long long)xx1 * (signed long long)xx2;\n\nprintf(\"r_whole = %lld\\n\",r_whole);\n</code></pre>\n<p>\u8f93\u51fa\u7684\u4e8b\u6709\u7b26\u53f7\u4e58\u6cd5\u7684\u7ed3\u679c\uff1a</p>\n<pre><code>r_whole = 1860719719092984036\n</code></pre>\n<p>\u7b2c\u4e00\u6bb5\u7a0b\u5e8f\u91cc\u6211\u4e0d\u662f\u5bf9 x1 \u8fdb\u884c\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u4e86\u5417</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/rookiemaster", 
        "name": "rookiemaster", 
        "avatar": "https://cdn.v2ex.com/avatar/b368/6614/659911_large.png?m=1769416716"
      }, 
      "url": "https://www.v2ex.com/t/1029725", 
      "date_modified": "2024-04-04T10:17:01+00:00", 
      "content_html": "<p>\u5c31\u4e00\u4e2a\u7b80\u5355\u7684 c \u7a0b\u5e8f:</p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\nint main()\n{\n    printf(\"Hello, World\\n\");\n}\n</code></pre>\n<p>\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u7f16\u8bd1\uff1a</p>\n<pre><code>riscv64-linux-gnu-gcc --static hello.c -o hello_riscv64\n</code></pre>\n<p>\u5c45\u7136\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c</p>\n<pre><code>&gt; ./hello_riscv64 \nHello, World\n</code></pre>\n<p>\u4f7f\u7528 qemu \u4e5f\u80fd\u8fd0\u884c\uff1a</p>\n<pre><code>&gt; qemu-riscv64-static  hello_riscv64 \nHello, World\n</code></pre>\n<p>readelf \u7ed3\u679c\uff1a</p>\n<pre><code>&gt; readelf -h hello_riscv64 \nELF Header:\n  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 \n  Class:                             ELF64\n  Data:                              2's complement, little endian\n  Version:                           1 (current)\n  OS/ABI:                            UNIX - System V\n  ABI Version:                       0\n  Type:                              EXEC (Executable file)\n  Machine:                           RISC-V\n  Version:                           0x1\n  Entry point address:               0x1054c\n  Start of program headers:          64 (bytes into file)\n  Start of section headers:          501880 (bytes into file)\n  Flags:                             0x5, RVC, double-float ABI\n  Size of this header:               64 (bytes)\n  Size of program headers:           56 (bytes)\n  Number of program headers:         7\n  Size of section headers:           64 (bytes)\n  Number of section headers:         28\n  Section header string table index: 27\n</code></pre>\n", 
      "date_published": "2024-04-04T10:10:33+00:00", 
      "title": "\u7528 riscv64- Linux -gnu-gcc \u7f16\u8bd1\u7684 c \u6587\u4ef6\u4e3a\u5565\u80fd\u5728 x8664 \u4e0b\u8fd0\u884c\uff1f", 
      "id": "https://www.v2ex.com/t/1029725"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/rookiemaster", 
        "name": "rookiemaster", 
        "avatar": "https://cdn.v2ex.com/avatar/b368/6614/659911_large.png?m=1769416716"
      }, 
      "url": "https://www.v2ex.com/t/1028174", 
      "title": "char *s = \"0123\"\u548c char s[] = \"0123\"\u7684\u533a\u522b", 
      "id": "https://www.v2ex.com/t/1028174", 
      "date_published": "2024-03-29T08:39:15+00:00", 
      "content_html": "<p>\u4e3a\u4ec0\u4e48\u524d\u8005\u4e0d\u53ef\u4ee5\u4fee\u6539\uff0c\u540e\u8005\u53ef\u4ee5\u4fee\u6539\uff0c\u662f\u56e0\u4e3a\u5b58\u50a8\u533a\u57df\u7684\u95ee\u9898\u5417\uff1f</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/rookiemaster", 
        "name": "rookiemaster", 
        "avatar": "https://cdn.v2ex.com/avatar/b368/6614/659911_large.png?m=1769416716"
      }, 
      "url": "https://www.v2ex.com/t/1026918", 
      "title": "\u6709\u4eba\u80fd\u5b8c\u6574\u5730\u89e3\u91ca\u4e00\u4e0b int (*daytab) [13]\u548c int *daytab[13]\u5417", 
      "id": "https://www.v2ex.com/t/1026918", 
      "date_published": "2024-03-25T11:43:55+00:00", 
      "content_html": ""
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/rookiemaster", 
        "name": "rookiemaster", 
        "avatar": "https://cdn.v2ex.com/avatar/b368/6614/659911_large.png?m=1769416716"
      }, 
      "url": "https://www.v2ex.com/t/1026188", 
      "title": "\u5728 c \u8bed\u8a00\u4e2d\uff0c int a;\u662f declaration \u8fd8\u662f definition", 
      "id": "https://www.v2ex.com/t/1026188", 
      "date_published": "2024-03-22T12:01:29+00:00", 
      "content_html": "<p>\u5df2\u77e5 extern int a;\u662f declaration</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/WilliamColton", 
        "name": "WilliamColton", 
        "avatar": "https://cdn.v2ex.com/avatar/3a5e/dae7/552863_large.png?m=1750001532"
      }, 
      "url": "https://www.v2ex.com/t/1026058", 
      "date_modified": "2024-03-22T04:35:16+00:00", 
      "content_html": "<p>\u4f7f\u7528\u7684 IDE \u662f CLion \uff0c\u7f16\u8bd1\u5668\u662f\u5176\u81ea\u5e26\u7684 <code>MinGW 11.0 w64</code></p>\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u4f7f\u7528 chatgpt \u52a0\u4e86\u6ce8\u91ca\uff0c\u4e3b\u8981\u7684\u95ee\u9898\u662f\uff1a</p>\n<p>\u5728\u76f4\u63a5\u7ed9\u5b9a\u8f93\u5165</p>\n<pre><code>8\n\n1 9 2 6 0 8 1 7\n</code></pre>\n<p>\u65f6\uff0c\u7ed3\u679c\u4e3a 0.</p>\n<p>\u800c\u518d\u6b21\u7ed9\u5b9a\u8f93\u5165</p>\n<pre><code>8\n\n1 9 2 6 90 8 1 7\n</code></pre>\n<p>\u65f6\uff0c\u7ed3\u679c\u8fd8\u662f 0.</p>\n<p>\u800c\u624b\u52a8\u4e00\u4e2a\u4e00\u4e2a\u8f93\u5165\u5219\u6b63\u5e38\u663e\u793a 1.</p>\n<p>\u867d\u7136\u63cf\u8ff0\u7684\u5f88\u79bb\u5947\uff0c\u4f46\u662f\u786e\u5b9e\u662f\u8fd9\u6837\uff0c\u5373\uff1a\u7b2c\u4e00\u6b21\u7684\u7ed3\u679c\u4f1a\u5f71\u54cd\u7b2c\u4e8c\u6b21\u7684\u7ed3\u679c\uff0c\u4f7f\u4e4b\u53d8\u6210\u7b2c\u4e00\u6b21\u7684\u7ed3\u679c</p>\n<p>\u6211\u95ee\u4e86\u6211\u4eec\u6559 C \u8bed\u8a00\u7684\u8001\u5e08\uff0c\u8fde\u4ed6\u4e5f\u4e0d\u77e5\u9053\u600e\u4e48\u56de\u4e8b\uff0c\u8bf4\u53ef\u80fd\u662f CLion \u7684\u95ee\u9898\uff0c\u4f46\u662f\u8fd9\u4e2a\u7b54\u6848\u5e76\u4e0d\u80fd\u4ee4\u6211\u4fe1\u670d\uff0c</p>\n<p>\u6545\u6765\u5bfb\u6c42\u5404\u4f4d V \u53cb\u5e2e\u52a9</p>\n<p>\u6c42\u5404\u4f4d V \u53cb\u89e3\u7b54 QAQ</p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a</p>\n<pre><code>#include &lt;stdio.h&gt;\n\nint main() {\n    int n;\n    scanf(\"%d\", &amp;n); // \u4ece\u6807\u51c6\u8f93\u5165\u4e2d\u8bfb\u53d6\u4e00\u4e2a\u6574\u6570\uff0c\u5b58\u50a8\u5230\u53d8\u91cf n \u4e2d\n\n    int min;\n    scanf(\"%d\", &amp;min); // \u5047\u8bbe\u8f93\u5165\u7684\u7b2c\u4e00\u4e2a\u6570\u4e3a\u6700\u5c0f\u503c\uff0c\u5b58\u50a8\u5230\u53d8\u91cf min \u4e2d\n    int num;\n    for (int i = 1; i &lt; n; i++) { // \u5faa\u73af\u8bfb\u53d6\u5269\u4f59\u7684 n-1 \u4e2a\u6574\u6570\n        scanf(\"%d\", &amp;num); // \u4ece\u6807\u51c6\u8f93\u5165\u4e2d\u8bfb\u53d6\u4e00\u4e2a\u6574\u6570\uff0c\u5b58\u50a8\u5230\u53d8\u91cf num \u4e2d\n        printf(\"%d\\n\", num); // \u5c06\u8bfb\u53d6\u7684\u6574\u6570\u6253\u5370\u5230\u6807\u51c6\u8f93\u51fa\uff0c\u4ee5\u6362\u884c\u7b26\u7ed3\u675f\n\n        if (num &lt; min) { // \u68c0\u67e5\u5f53\u524d\u8bfb\u53d6\u7684\u6574\u6570\u662f\u5426\u6bd4\u6700\u5c0f\u503c\u5c0f\n            min = num; // \u66f4\u65b0\u6700\u5c0f\u503c\u4e3a\u5f53\u524d\u8bfb\u53d6\u7684\u6574\u6570\n        }\n    }\n    printf(\"%d\", min); // \u6253\u5370\u6700\u5c0f\u503c\u5230\u6807\u51c6\u8f93\u51fa\n\n    return 0; // \u8fd4\u56de 0 \u8868\u793a\u7a0b\u5e8f\u6b63\u5e38\u7ed3\u675f\n}\n\n</code></pre>\n", 
      "date_published": "2024-03-22T04:33:46+00:00", 
      "title": "\u4e00\u4e2a\u7b80\u5355\uff08\u5947\u602a\uff09\u7684 C \u8bed\u8a00\u95ee\u9898", 
      "id": "https://www.v2ex.com/t/1026058"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/rookiemaster", 
        "name": "rookiemaster", 
        "avatar": "https://cdn.v2ex.com/avatar/b368/6614/659911_large.png?m=1769416716"
      }, 
      "url": "https://www.v2ex.com/t/1025538", 
      "title": "c \u8bed\u8a00\u4e2d\u6253\u5370\u6307\u9488\u7684\u503c\u6253\u5370\u7684\u662f OS \u5206\u914d\u7684\u865a\u62df\u5730\u5740\u7684\u503c\u5417\uff1f\u8981\u600e\u4e48\u77e5\u9053 OS \u7ed9\u8fd9\u4e2a c \u7a0b\u5e8f\u8fdb\u7a0b\u5206\u914d\u7684\u865a\u62df\u5730\u5740\u7684\u5927\u5c0f\u5462\uff1f", 
      "id": "https://www.v2ex.com/t/1025538", 
      "date_published": "2024-03-20T12:33:52+00:00", 
      "content_html": "<p>\u5e76\u4e14\u5982\u4f55\u77e5\u9053\u54ea\u4e00\u5757\u5185\u5b58\u5927\u5c0f\u662f\u53ef\u4ee5\u8bfb\u53ef\u4ee5\u5199\uff0c\u4ee5\u907f\u514d\u51fa\u73b0\u4e0b\u9762\u7a0b\u5e8f\u7684 Segmentation Fault \u5462\uff1f</p>\n<pre><code class=\"language-c\">#include&lt;stdio.h&gt;\nint main(){\n\tint *p = (int *)0x1;\n    printf(\"%p\\n\", p);\n    *p = 1;           // segmentation fault\n    printf(\"%d\", *p); // segmentation fault\n}\n\n</code></pre>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/rookiemaster", 
        "name": "rookiemaster", 
        "avatar": "https://cdn.v2ex.com/avatar/b368/6614/659911_large.png?m=1769416716"
      }, 
      "url": "https://www.v2ex.com/t/1025303", 
      "date_modified": "2024-03-20T02:31:44+00:00", 
      "content_html": "<p>\u7a0b\u5e8f\u5982\u4e0b\uff1a</p>\n<pre><code class=\"language-c\">int main()\n{\n    system(\"echo hello world\");\n}\n</code></pre>\n<p>\u4f7f\u7528 gcc \u7f16\u8bd1\u65f6\u4f1a\u8b66\u544a\u627e\u4e0d\u5230 system \u7684\u58f0\u660e\uff1a<br/></p>\n<pre><code>DoubleHash.c: In function \u2018main\u2019:\nDoubleHash.c:3:5: warning: implicit declaration of function \u2018system\u2019 [-Wimplicit-function-declaration]\n    3 |     system(\"echo hello world\");\n      |     ^~~~~~\n</code></pre>\n<p>\u4f46\u662f\u7a0b\u5e8f\u4ecd\u7136\u53ef\u4ee5\u8fd0\u884c\uff0c\u6211\u60f3\u77e5\u9053\u7f16\u8bd1\u5668\u662f\u600e\u4e48\u627e\u5230 system \u7684\u5b9a\u4e49\u7684\uff1f</p>\n", 
      "date_published": "2024-03-20T02:23:35+00:00", 
      "title": "gcc \u662f\u600e\u4e48\u627e\u5230 system \u51fd\u6570\u7684\u5b9a\u4e49\uff08\u5b9e\u73b0\uff09\u7684\uff1f", 
      "id": "https://www.v2ex.com/t/1025303"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/monkeyNik", 
        "name": "monkeyNik", 
        "avatar": "https://cdn.v2ex.com/avatar/d196/0d1a/499929_large.png?m=1697247708"
      }, 
      "url": "https://www.v2ex.com/t/1025025", 
      "title": "\u7528 C \u5b9e\u73b0\u8f7b\u91cf\u7ea7\u8868\u8fbe\u5f0f\u5b8c\u6210\u7b56\u7565\u5b9a\u5236\u5316\u548c\u6a21\u677f\u5185\u5bb9\u751f\u6210", 
      "id": "https://www.v2ex.com/t/1025025", 
      "date_published": "2024-03-19T04:39:01+00:00", 
      "content_html": "<p>\u672c\u6587\u4ecb\u7ecd\u5f00\u6e90 C \u8bed\u8a00\u5e93<a href=\"https://github.com/Water-Melon/Melon\" rel=\"nofollow\">Melon</a>\u7684<a href=\"http://doc.melonc.io/cn/expr.html\" rel=\"nofollow\">\u8868\u8fbe\u5f0f\u7ec4\u4ef6</a>\uff0c\u8be5\u7ec4\u4ef6\u5b9e\u73b0\u4e86\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u8868\u8fbe\u5f0f\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u5b9a\u5236\u5316\u5c5e\u4e8e\u81ea\u5df1\u7684\u4e13\u5c5e\u53d8\u91cf\u548c\u51fd\u6570\u89e3\u6790\u5668\u3002\u8be5\u6a21\u5757\u53ef\u4ee5\u7528\u4e8e\u6587\u672c\u6a21\u677f\u5185\u5bb9\u66ff\u6362\u4ee5\u53ca\u4e00\u4e9b\u7b80\u5355\u7684\u6307\u4ee4\u6a21\u5f0f\u7f16\u7a0b\u573a\u666f\uff08\u4f8b\u5982\u7f16\u5199\u7b56\u7565\uff09\u3002</p>\n<p>\u4e0b\u9762\u662f\u8be5\u7ec4\u4ef6\u652f\u6301\u7684\u8bed\u6cd5\uff1a</p>\n<pre><code>abc   --\u8fd9\u662f\u4e00\u4e2a\u53d8\u91cf\n\"abc\" --\u8fd9\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u5e38\u91cf\n'abc' --\u8fd9\u4e5f\u662f\u5b57\u7b26\u4e32\u5e38\u91cf\n1     --\u6574\u6570\n1.2   --\u6d6e\u70b9\u6570\n0xa   --\u5341\u516d\u8fdb\u5236\u6574\u6570\n0311  --\u516b\u8fdb\u5236\u6574\u6570\n\nconcat(abc, bcd) --\u8fd9\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u53c2\u6570\u6709\u4e24\u4e2a\uff0c\u90fd\u662f\u53d8\u91cf\nconcat(abc, \"bcd\") --\u8fd9\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u53c2\u6570\u6709\u4e24\u4e2a\uff0c\u4e00\u4e2a\u662f\u53d8\u91cf\uff0c\u4e00\u4e2a\u662f\u5e38\u91cf\nconcat(1, \"bcd\") --\u4e24\u4e2a\u53c2\u6570\u90fd\u662f\u5e38\u91cf\nconcat(\"abc\", concat(bcd, \"efg\")) --\u8fd9\u4e2a\u4f8b\u5b50\u5c55\u793a\u4e86\u51fd\u6570\u5d4c\u5957\u8c03\u7528\nconcat(\"abc\", concat(bcd, \"efg\")) aaa concat(\"bcd\", concat(efg, \"hij\")) --\u8fd9\u4e2a\u4f8b\u5b50\u5c55\u793a\u8fd0\u884c\u591a\u4e2a\u8868\u8fbe\u5f0f\n</code></pre>\n<p>\u7b80\u5355\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f\u8bed\u6cd5\u652f\u6301\u4e09\u79cd\u7c7b\u578b\u5185\u5bb9\uff1a</p>\n<ul>\n<li>\u5e38\u91cf</li>\n<li>\u53d8\u91cf</li>\n<li>\u51fd\u6570</li>\n</ul>\n<p>\u5e76\u4e14\u51fd\u6570\u652f\u6301\u5d4c\u5957\u8c03\u7528\u3002</p>\n<p>\u6b64\u5916\uff0c\u53ef\u4ee5\u4e00\u6b21\u6267\u884c\u591a\u4e2a\u8868\u8fbe\u5f0f\uff0c\u6240\u6709\u8868\u8fbe\u5f0f\u7684\u6267\u884c\u7ed3\u679c\u4e3a\u6700\u540e\u4e00\u4e2a\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\u3002</p>\n<p>\u6211\u4eec\u5206\u522b\u5bf9\u7740\u4e09\u79cd\u7c7b\u578b\u5206\u522b\u8bf4\u660e\uff1a</p>\n<h4>\u5e38\u91cf</h4>\n<p>\u8fd9\u4e2a\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u5c31\u662f\u5b57\u9762\u91cf\uff0c\u4e3b\u8981\u652f\u6301\uff1a\u5b57\u7b26\u4e32\u3001\u6574\u6570\u548c\u6d6e\u70b9\u6570\u3002\u5176\u4e2d\uff0c\u6574\u6570\u652f\u6301\u5341\u8fdb\u5236\u5199\u6cd5\u3001\u516b\u8fdb\u5236\u5199\u6cd5\u548c\u5341\u516d\u8fdb\u5236\u5199\u6cd5\u3002</p>\n<h4>\u53d8\u91cf</h4>\n<p>\u53d8\u91cf\u987e\u540d\u601d\u4e49\uff0c\u5c31\u662f\u5176\u503c\u53ef\u53d8\u3002\u4f46\u7531\u4e8e\u8868\u8fbe\u5f0f\u6bd4\u8f83\u7b80\u5355\uff0c\u4e14\u5e94\u7528\u573a\u666f\u4e0e\u5e38\u89c4\u7f16\u7a0b\u8bed\u8a00\u4e0d\u540c\uff0c\u56e0\u6b64\u4e0d\u662f\u901a\u8fc7<code>=</code>\u6765\u8fdb\u884c\u8d4b\u503c\u7684\uff0c\u800c\u662f\u901a\u8fc7\u56de\u8c03\u51fd\u6570\uff0c\u7531\u4f7f\u7528\u8005\u51b3\u5b9a\u8be5\u8fd4\u56de\u4f55\u503c\u4f5c\u4e3a\u8be5\u53d8\u91cf\u7684\u503c\u3002</p>\n<h4>\u51fd\u6570</h4>\n<p>\u4e0e\u53d8\u91cf\u4e00\u6837\uff0c\u51fd\u6570\u7684\u884c\u4e3a\u5b8c\u5168\u7531\u56de\u8c03\u51fd\u6570\u51b3\u5b9a\uff0c\u4e5f\u5c31\u662f\u8bf4\u7531\u4f7f\u7528\u8005\u81ea\u884c\u5b9a\u5236\u3002</p>\n<h3>\u4f8b\u5b50</h3>\n<p>\u6211\u4eec\u770b\u4e00\u4e2a\u793a\u4f8b</p>\n<pre><code class=\"language-c\">#include \"mln_expr.h\"\n#include \"mln_log.h\"\n#include &lt;stdio.h&gt;\n\nstatic mln_expr_val_t *func_expr_handler(mln_string_t *name, int is_func, mln_array_t *args, void *data)\n{\n    mln_expr_val_t *v, *p;\n    int i;\n    mln_string_t *s1 = NULL, *s2, *s3;\n\n    if (!is_func)\n        return mln_expr_val_new(mln_expr_type_string, name, NULL);\n\n    for (i = 0, v = p = mln_array_elts(args); i &lt; mln_array_nelts(args); v = p + (++i)) {\n        if (s1 == NULL) {\n            s1 = mln_string_ref(v-&gt;data.s);\n            continue;\n        }\n        s2 = v-&gt;data.s;\n        s3 = mln_string_strcat(s1, s2);\n        mln_string_free(s1);\n        s1 = s3;\n    }\n\n    v = mln_expr_val_new(mln_expr_type_string, s1, NULL);\n    mln_string_free(s1);\n\n    return v;\n}\n\nint main(void)\n{\n    mln_string_t func_exp = mln_string(\"concat('abc', concat(aaa, 'bbb')) ccc concat('eee', concat(bbb, 'fff'))\");\n\n    mln_expr_val_t *v;\n\n    v = mln_expr_run(&amp;func_exp, func_expr_handler, NULL);\n    if (v == NULL) {\n        mln_log(error, \"run failed\\n\");\n        return -1;\n    }\n    mln_log(debug, \"%d %S\\n\", v-&gt;type, v-&gt;data.s);\n    mln_expr_val_free(v);\n\n    return 0;\n}\n</code></pre>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7efc\u5408\u4e00\u70b9\u7684\u4f8b\u5b50\uff0c\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u5305\u542b\u4e86\u51fd\u6570\u5d4c\u5957\u8c03\u7528\u3001\u53d8\u91cf\u3001\u591a\u8868\u8fbe\u5f0f\u6267\u884c\u3002</p>\n<p>\u8868\u8fbe\u5f0f\u4e2d\u7684\u53d8\u91cf\u548c\u51fd\u6570\u90fd\u7531<code>func_expr_handler</code>\u8fd9\u4e2a\u56de\u8c03\u51fd\u6570\u6765\u89e3\u6790\u3002\u5bf9\u4e8e\u53d8\u91cf\uff0c\u56de\u8c03\u51fd\u6570\u76f4\u63a5\u8fd4\u56de\u53d8\u91cf\u7684\u540d\u5b57\u4f5c\u4e3a\u53d8\u91cf\u7684\u503c\u3002\u800c\u5bf9\u4e8e\u51fd\u6570\uff0c\u56de\u8c03\u51fd\u6570\u5219\u662f\u5c06\u51fd\u6570\u53c2\u6570\u62fc\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u51fd\u6570\u7684\u8fd4\u56de\u503c\u3002</p>\n<p>\u7531\u4e8e\u672c\u4f8b\u4e2d\u5b58\u5728\u4e09\u4e2a\u8868\u8fbe\u5f0f\uff1a</p>\n<ul>\n<li><code>concat('abc', concat(aaa, 'bbb'))</code></li>\n<li><code>ccc</code></li>\n<li><code>concat('eee', concat(bbb, 'fff'))</code></li>\n</ul>\n<p>\u524d\u9762\u6211\u4eec\u8bf4\u5230\u8fc7\uff0c<code>mln_expr_run</code>\u7684\u8fd4\u56de\u503c\u662f\u6700\u540e\u4e00\u4e2a\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u6240\u4ee5\u6700\u7ec8\u7ec8\u7aef\u7684\u8f93\u51fa\u5c31\u662f\uff1a</p>\n<pre><code>eeebbbfff\n</code></pre>\n<p>\u4e5f\u6b63\u5982\u8fd9\u4e2a\u4f8b\u5b50\u6240\u793a\uff0c\u8868\u8fbe\u5f0f\u7ec4\u4ef6\u53ea\u662f\u63d0\u4f9b\u4e86\u4e00\u79cd\u5bf9\u6587\u672c\u683c\u5f0f\u7684\u89c4\u8303\uff0c\u800c\u5177\u4f53\u6709\u54ea\u4e9b\u51fd\u6570\u548c\u53d8\u91cf\u90fd\u5b8c\u5168\u4ea4\u7ed9\u56de\u8c03\u51fd\u6570\u6765\u51b3\u5b9a\uff0c\u4e5f\u5c31\u662f\u4ea4\u7ed9\u4e86\u4f7f\u7528\u8005\u51b3\u5b9a\u3002\u5e76\u4e14\u8fd9\u4e2a\u7ec4\u4ef6\u5e76\u4e0d\u50cf\u5b8c\u6574\u7684\u7f16\u7a0b\u8bed\u8a00\u90a3\u6837\u529f\u80fd\u7e41\u91cd\uff0c\u56e0\u6b64\u6bd4\u8f83\u9002\u5408\u4e00\u4e9b\u5c0f\u578b\u529f\u80fd\u6574\u5408\u6216\u8005\u6a21\u677f\u66ff\u6362\u4e4b\u7c7b\u7684\u573a\u666f\u3002</p>\n<p>\u6a21\u677f\u66ff\u6362\u53ef\u4ee5\u53c2\u8003 web \u524d\u7aef\u7684\u90a3\u4e9b\u6a21\u677f\uff0c\u4f8b\u5982\uff1atwig \u3001mustache \u7b49\u3002</p>\n<p>\u5c0f\u529f\u80fd\u6574\u5408\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u4f8b\u5982\u5728\u5bf9\u67d0\u79cd\u7f51\u7edc\u901a\u4fe1\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u62a5\u6587\u63d0\u53d6\u67d0\u4e9b\u5b57\u6bb5\uff0c\u7136\u540e\u5bf9\u5b57\u6bb5\u5904\u7406\uff0c\u7136\u540e\u518d\u505a\u9a8c\u8bc1\u3002\u90a3\u4e48\u63d0\u53d6\u3001\u5904\u7406\u3001\u9a8c\u8bc1\u5c31\u53ef\u4ee5\u88ab\u5c01\u88c5\u6210\u4e09\u4e2a\u51fd\u6570\u3002\u8fd9\u4e09\u4e2a\u51fd\u6570\u662f\u4e09\u79cd\u884c\u4e3a\uff0c\u800c\u4e0d\u662f\u7b56\u7565\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e09\u79cd\u884c\u4e3a\u5e94\u8bbe\u6210\u8868\u8fbe\u5f0f\u7ec4\u4ef6\u4e2d\u7684\u4e09\u4e2a\u51fd\u6570\uff0c\u7136\u540e\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7\u5bf9\u8fd9\u4e09\u4e2a\u51fd\u6570\u7684\u7ec4\u5408\u5e94\u7528\u6765\u5b9e\u73b0\u7b56\u7565\u3002\u5bf9\u4e8e\u7b56\u7565\u7684\u6539\u53d8\uff0c\u6211\u4eec\u5e76\u4e0d\u9700\u8981\u4fee\u6539 C \u4ee3\u7801\uff0c\u53ea\u9700\u8981\u5c06\u7b56\u7565\u7684\u6587\u672c\u5185\u5bb9\uff08\u4e5f\u5c31\u662f\u8fd9\u4e9b\u8868\u8fbe\u5f0f\uff09\u505a\u4e00\u4e9b\u4fee\u6539\u5373\u53ef\u3002</p>\n<p>\u611f\u8c22\u9605\u8bfb\uff01</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/rookiemaster", 
        "name": "rookiemaster", 
        "avatar": "https://cdn.v2ex.com/avatar/b368/6614/659911_large.png?m=1769416716"
      }, 
      "url": "https://www.v2ex.com/t/1024844", 
      "title": "c \u8bed\u8a00\u662f\u5982\u4f55\u7ed9\u6c49\u5b57\u7f16\u7801\u7684\uff1f", 
      "id": "https://www.v2ex.com/t/1024844", 
      "date_published": "2024-03-18T11:19:36+00:00", 
      "content_html": "<p>\u5982\u4e0b\u7a0b\u5e8f\uff1a</p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\nint main()\n{\n    char s[7] = \"\u4e03 123\";\n    int i;\n    for (i = 0; i &lt; 7; i++)\n    {\n        printf(\"%d,\", s[i]);\n    }\n}\n</code></pre>\n<p>\u6253\u5370\u51fa\u6765\u7684\u7ed3\u679c\u662f\uff1a-28,-72,-125,49,50,51,0, <br/>\n\u524d\u9762\u7684-28,-72,-125 \u6b63\u662f\u4e03\u7684 utf8 \u7f16\u7801 <br/>\n\u8981\u662f\u6211\u60f3\u6253\u5370\u51fa\u4e03\u7684 gbk \u7f16\u7801\u5e94\u8be5\u600e\u4e48\u529e\uff1f</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/nnegier", 
        "name": "nnegier", 
        "avatar": "https://cdn.v2ex.com/gravatar/00b9dc80a372050eec8fbfa5200a6186?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1022210", 
      "date_modified": "2024-03-10T05:51:40+00:00", 
      "content_html": "<p>\u6211\u770b\u5230\u4e00\u4e2a\u63cf\u8ff0\uff0c\u201c\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6211\u4eec\u9700\u8981\u628a moon.o \u3001sun.o \u3001earth.o \u8fd9 3 \u4e2a\u4e1c\u897f\u5f04\u6210\u4e00\u4e2a\u4e1c\u897f\u3002\u8fd9\u79cd\u65b9\u6cd5 \u5c31\u662f \u9759\u6001\u5e93 \u8ddf \u52a8\u6001\u5e93\uff0c\u9759\u6001\u5e93 \u662f\u53ef\u4ee5\u94fe\u63a5\u8fdb\u53bb \u7a0b\u5e8f\u81ea\u8eab\uff0c\u52a8\u6001\u5e93\u662f\u5171\u4eab\u5e93\uff0c\u53ef\u4ee5\u7531\u591a\u4e2a\u7a0b\u5e8f\u5171\u4eab\u8282\u7701\u7a7a\u95f4\uff0c\u52a8\u6001\u5e93\u53ea\u6709\u7528\u5230\u7684\u65f6\u5019\u624d\u4f1a\u52a0\u8f7d\u3002\u201d</p>\n<p>\u5b83\u8fd9\u91cc\u7684\u7a0b\u5e8f\u662f\u6307\u5355\u4e2a\u5e94\u7528\u8fd8\u662f\u6307\u5355\u4e2a C \u8bed\u8a00\u6587\u4ef6\u5440\uff1f\u5982\u679c\u662f\u5355\u4e2a\u5e94\u7528\uff0c\u600e\u4e48\u8bf4\u591a\u4e2a\u7a0b\u5e8f\u5171\u4eab\u5462\uff1b\u5982\u679c\u662f\u8bf4\u5355\u4e2a C \u6587\u4ef6\uff0c\u90a3\u6240\u8c13\u7684\u5171\u4eab\u53c8\u662f\u6307\u5565\u5462\uff1b\u53cd\u6b63\u6211\u6a2a\u7ad6\u90fd\u5f04\u4e0d\u6e05\uff0c\u53ea\u77e5\u9053\u90fd\u80fd\u7528\u3002\uff08\u6211\u4e2a\u4eba\u80cc\u666f\u662f\u4e0a\u5c42 Android \u5f00\u53d1\uff0c\u4f7f\u7528\u7684\u65f6\u5019\u611f\u89c9\u6ca1\u5565\u592a\u5927\u533a\u522b\uff0c\u5f53\u7136\u4e86\u9759\u6001\u5e93\u5feb\u3001\u52a8\u6001\u5e93\u6162\u8fd9\u4e2a\u6211\u80fd\u7406\u89e3\uff0c\u50cf\u7a7a\u95f4\u8282\u7701\u8fd9\u4e2a\u6211\u6ca1\u80fd\u7406\u89e3\uff09</p>\n", 
      "date_published": "2024-03-09T22:20:25+00:00", 
      "title": "\u8fd8\u662f\u4e0d\u592a\u7406\u89e3 C \u9759\u6001\u5e93\u548c\u52a8\u6001\u5e93\uff1f", 
      "id": "https://www.v2ex.com/t/1022210"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/Openbfdev", 
        "name": "Openbfdev", 
        "avatar": "https://cdn.v2ex.com/avatar/9c7e/179e/679237_large.png?m=1709800181"
      }, 
      "url": "https://www.v2ex.com/t/1021646", 
      "title": "\u5f00\u6e90 C \u5e93 bfdev\uff1a MPI \u5927\u6570\u8fd0\u7b97", 
      "id": "https://www.v2ex.com/t/1021646", 
      "date_published": "2024-03-07T17:33:56+00:00", 
      "content_html": "<p>\u672c\u6587\u5c55\u793a\u5f00\u6e90 C \u5e93 bfdev \u7684\u5927\u6570\u8fd0\u7b97\u6a21\u5757\u3002\u6211\u4eec\u5c06\u5206\u522b\u5728 x86 Linux \u5e73\u53f0\u548c py32f030 \u4e3a\u4ee3\u8868\u7684\u5d4c\u5165\u5f0f\u5e73\u53f0\u4e0a\u5206\u522b\u8fdb\u884c\u6f14\u793a\uff0c\u5e76\u8fdb\u884c\u6027\u80fd\u6d4b\u8bd5\u3002</p>\n<p>\u5173\u4e8e bfdev \u5e93\uff0c\u8fd9\u662f\u4e00\u4e2a\u5f00\u6e90\u7684 C \u8bed\u8a00\u7b97\u6cd5\u5e93, \u5b83\u5177\u6709\uff1a\u826f\u597d\u7684\u53ef\u79fb\u690d\u6027\uff0c\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u6cd5\u8bbe\u8ba1\u3001\u5b89\u88c5\u90e8\u7f72\u7b80\u5355\u7b49\u7b49\u4f18\u52bf\u3002</p>\n<p><a href=\"https://github.com/openbfdev/bfdev\" rel=\"nofollow\">Github \u4ed3\u5e93\u94fe\u63a5</a></p>\n<h2>\u7b80\u4ecb</h2>\n<p><strong>MPI</strong> \u5373 Multi precision integer \uff08\u591a\u7cbe\u5ea6\u6574\u6570\uff09\uff0c\u5c31\u662f\u5bf9\u5f88\u5927\u7684\u6570\u8fdb\u884c\u4e00\u7cfb\u5217\u7684\u8fd0\u7b97\u3002\u5728\u6570\u5b66\u4e2d\uff0c\u6570\u7684\u5927\u5c0f\u662f\u6ca1\u6709\u4e0a\u9650\u7684\uff0c\u4f46\u662f\u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u7531\u4e8e\u53d7 ALU \u5b57\u957f\u7684\u9650\u5236\uff0c\u5904\u7406\u5668\u65e0\u6cd5\u5bf9\u5176\u8fdb\u884c\u76f4\u63a5\u8ba1\u7b97\uff0c\u6211\u4eec\u5c31\u9700\u8981\u7528\u5230\u591a\u7cbe\u5ea6\u6574\u6570\u7b97\u6cd5\u3002</p>\n<h2>\u4f7f\u7528</h2>\n<p>\u6211\u4eec\u5148\u7ed9\u51fa\u4e24\u4e2a\u5e73\u53f0\u57fa\u4e8e <strong>MPI</strong> \u4f7f\u7528 <strong>machin \u516c\u5f0f</strong> \u8ba1\u7b97\u5706\u5468\u7387\u7684\u6d4b\u8bd5\u4ee3\u7801\uff0c\u518d\u8fdb\u884c\u8bf4\u660e\u3002</p>\n<h4>bfdev \u4ed3\u5e93 <a href=\"https://github.com/openbfdev/bfdev/blob/devel/examples/mpi/machin.c\" rel=\"nofollow\">\u793a\u4f8b</a></h4>\n<pre><code class=\"language-c\">#define MODULE_NAME \"mpi-machin\"\n#define bfdev_log_fmt(fmt) MODULE_NAME \": \" fmt\n\n#include &lt;stdio.h&gt;\n#include &lt;bfdev/mpi.h&gt;\n#include &lt;bfdev/log.h&gt;\n#include \"../time.h\"\n#include \"helper.h\"\n\n#define TEST_LEN 10000\n#define TEST_SIZE (TEST_LEN / 4 + 1)\n#define TEST_LOOP (TEST_LEN / 1.39793 + 1)\n#define PRINT_RESULT 1\n\nint main(int argc, const char *argv[])\n{\n    bfdev_mpi_t *vw, *vs, *vv, *vq;\n    unsigned int k;\n    int retval;\n\n    if (!((vw = bfdev_mpi_create(NULL)) &amp;&amp;\n          (vs = bfdev_mpi_create(NULL)) &amp;&amp;\n          (vv = bfdev_mpi_create(NULL)) &amp;&amp;\n          (vq = bfdev_mpi_create(NULL))))\n        return 1;\n\n    /**\n     * Machin-like formula:\n     *  PI = 16arctan(1/5) - 4arctan(1/239)\n     *\n     * These formulas are used in conjunction with Gregory's\n     * series, the Taylor series expansion for arctangent:\n     *  arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 + ...\n     */\n\n    if ((retval = bfdev_mpi_seti(vw, 16 * 5)) ||\n        (retval = bfdev_mpi_seti(vv, 4 * 239)) ||\n        (retval = bfdev_mpi_seti(vq, 10000)))\n        return retval;\n\n    for (k = 0; k &lt; TEST_SIZE; ++k) {\n        if ((retval = bfdev_mpi_mul(vw, vw, vq)) ||\n            (retval = bfdev_mpi_mul(vv, vv, vq)))\n            return retval;\n    }\n\n    bfdev_log_info(\"Convergence Machin %d:\\n\", TEST_LEN);\n    EXAMPLE_TIME_STATISTICAL(\n        for (k = 1; k &lt;= TEST_LOOP; ++k) {\n            if ((retval = bfdev_mpi_divi(vw, vw, vw, 5 * 5)) ||\n                (retval = bfdev_mpi_divi(vv, vv, vv, 239 * 239)) ||\n                (retval = bfdev_mpi_sub(vq, vw, vv)) ||\n                (retval = bfdev_mpi_divi(vq, vq, vq, 2 * k - 1)))\n                return retval;\n\n            if (k &amp; 1)\n                retval = bfdev_mpi_add(vs, vs, vq);\n            else\n                retval = bfdev_mpi_sub(vs, vs, vq);\n\n            if (retval)\n                return retval;\n        }\n        0;\n    );\n\n#if PRINT_RESULT\n    char *result;\n\n    result = print_num(vs, 10);\n    if (!result)\n        return 1;\n\n    printf(\"%c.\", *result);\n    puts(result + 1);\n    free(result);\n#endif\n\n    bfdev_mpi_destory(vw);\n    bfdev_mpi_destory(vs);\n    bfdev_mpi_destory(vv);\n    bfdev_mpi_destory(vq);\n\n    return 0;\n}\n</code></pre>\n<p>\u4ee5\u4e0b\u662f\u8fd0\u7b97 pi \u540e 10000 \u4f4d\u7684\u7ed3\u679c\uff0c\u5171\u4f7f\u7528\u4e86 0.36 \u79d2\u3002</p>\n<pre><code class=\"language-shell\">\u276f ./build/examples/mpi/mpi-machin\n[info] mpi-machin: Convergence Machin 10000:\n[info] mpi-machin:      real time: 0.360000\n[info] mpi-machin:      user time: 0.350000\n[info] mpi-machin:      kern time: 0.000000\n3.14159\n...\n</code></pre>\n<h4>py32f030 \u5e73\u53f0 <a href=\"https://github.com/openbfdev-devel/py32f0xx-bfdev/blob/master/examples/benchmark/mpi.c\" rel=\"nofollow\">\u793a\u4f8b</a></h4>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;stdint.h&gt;\n#include &lt;errno.h&gt;\n#include &lt;bfdev.h&gt;\n\n#include \"main.h\"\n#include \"py32f0xx_hal.h\"\n\n#define TEST_LEN 100\n#define TEST_SIZE (TEST_LEN / 4 + 1)\n#define TEST_LOOP (TEST_LEN / 1.39793 + 1)\n\nint mpi_benchmark(void)\n{\n    uint32_t start, time;\n    bfdev_mpi_t *vw, *vs, *vv, *vq;\n    unsigned int k;\n    int retval;\n\n    if (!((vw = bfdev_mpi_create(NULL)) &amp;&amp;\n          (vs = bfdev_mpi_create(NULL)) &amp;&amp;\n          (vv = bfdev_mpi_create(NULL)) &amp;&amp;\n          (vq = bfdev_mpi_create(NULL))))\n        return 1;\n\n    if ((retval = bfdev_mpi_seti(vw, 16 * 5)) ||\n        (retval = bfdev_mpi_seti(vv, 4 * 239)) ||\n        (retval = bfdev_mpi_seti(vq, 10000)))\n        return retval;\n\n    for (k = 0; k &lt; TEST_SIZE; ++k) {\n        if ((retval = bfdev_mpi_mul(vw, vw, vq)) ||\n            (retval = bfdev_mpi_mul(vv, vv, vq)))\n            return retval;\n    }\n\n    bfdev_log_info(\"Convergence Machin %d:\\n\", TEST_LEN);\n    start = HAL_GetTick();\n    for (k = 1; k &lt;= TEST_LOOP; ++k) {\n        if ((retval = bfdev_mpi_divi(vw, vw, vw, 5 * 5)) ||\n            (retval = bfdev_mpi_divi(vv, vv, vv, 239 * 239)) ||\n            (retval = bfdev_mpi_sub(vq, vw, vv)) ||\n            (retval = bfdev_mpi_divi(vq, vq, vq, 2 * k - 1)))\n            return retval;\n\n        if (k &amp; 1)\n            retval = bfdev_mpi_add(vs, vs, vq);\n        else\n            retval = bfdev_mpi_sub(vs, vs, vq);\n\n        if (retval)\n            return retval;\n\n        iwdg_touch();\n    }\n\n    bfdev_mpi_destory(vw);\n    bfdev_mpi_destory(vs);\n    bfdev_mpi_destory(vv);\n    bfdev_mpi_destory(vq);\n    iwdg_touch();\n\n    time = HAL_GetTick() - start;\n    bfdev_log_notice(\"Total time: %lu.%lus\\n\", time / 1000, time % 1000);\n\n    return 0;\n}\n</code></pre>\n<p>\u4ee5\u4e0b\u662f\u8fd0\u7b97\u7ed3\u679c\uff0c\u7531\u4e8e py32f030 \u53ea\u6709 4KiB RAM \uff0c\u6211\u4eec\u8fd9\u91cc\u53ea\u8ba1\u7b97 100 \u4f4d\u3002</p>\n<pre><code class=\"language-shell\">[info] benchmark: Benchmark for PY32F0xx.\n[info] benchmark: Bfdev version: 1.0.1-devel\n[info] benchmark: This may take a few minutes...\n\n[info] Convergence Machin 100:\n[notice] Total time: 0.21s\n...\n</code></pre>\n<p>\u6211\u4eec\u8ba1\u7b97\u7684\u5927\u4f53\u6d41\u7a0b\u5982\u4e0b\uff1a</p>\n<ol>\n<li>\u9996\u5148\u4f7f\u7528 <strong>bfdev_mpi_create</strong> \u521b\u5efa <strong>MPI</strong> \u5bf9\u8c61</li>\n<li>\u5bf9 <strong>MPI</strong> \u5bf9\u8c61\u4f7f\u7528 <strong>bfdev_mpi_seti</strong> \u65b9\u6cd5\u8d4b\u503c</li>\n<li>\u4f7f\u7528\u8ba1\u7b97\u65b9\u6cd5\u8fdb\u884c\u8fd0\u7b97</li>\n<li>\u8f93\u51fa\u5b8c\u6210\u5e76\u9000\u51fa</li>\n</ol>\n<p>bfdev \u4e2d\uff0c\u4f7f\u7528 <strong>MPI</strong> \u9700\u8981\u5f15\u5165 <code>&lt;bfdev/mpi.h&gt;</code> \u5934\u6587\u4ef6\uff0c\u6216\u8005\u5f15\u5165 <code>&lt;bfdev.h&gt;</code> \u9876\u5c42\u5934\u6587\u4ef6\u4e5f\u53ef\u4ee5\u3002</p>\n<p>\u8fd9\u91cc\u8981\u91cd\u70b9\u4ecb\u7ecd\u4e00\u4e0b <code>bfdev_mpi_create(alloc)</code> \u51fd\u6570\uff0c\u5b83\u4f7f\u7528\u4e86 bfdev \u7684 allocator \u517c\u5bb9\u5c42\uff0c\u4f20\u5165 NULL \u5c06\u4f7f\u7528\u7cfb\u7edf\u9ed8\u8ba4\u5185\u5b58\u5206\u914d\u5668\uff0c\u7528\u6237\u4e5f\u53ef\u4ee5\u4f7f\u7528\u81ea\u5df1\u7684\u5185\u5b58\u6c60\u4e3a <strong>MPI</strong> \u5206\u914d\u5185\u5b58\u3002</p>\n<h2>\u7ed3\u8bed</h2>\n<p>\u6b22\u8fce\u5404\u4f4d\u611f\u5174\u8da3\u7684\u8bfb\u8005\u53bb\u8bbf\u95ee bfdev \u4ed3\u5e93\u3002</p>\n<p><a href=\"https://openbfdev.github.io/bfdev-docs/\" rel=\"nofollow\">bfdev \u6587\u6863</a></p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/monkeyNik", 
        "name": "monkeyNik", 
        "avatar": "https://cdn.v2ex.com/avatar/d196/0d1a/499929_large.png?m=1697247708"
      }, 
      "url": "https://www.v2ex.com/t/1021620", 
      "title": "C \u8bed\u8a00\u4e2d\u7684\u9762\u5411\u5207\u9762\u7f16\u7a0b(AOP)", 
      "id": "https://www.v2ex.com/t/1021620", 
      "date_published": "2024-03-07T14:11:06+00:00", 
      "content_html": "<h2>\u6982\u5ff5</h2>\n<p>\u9996\u5148\u7ed9\u51fa\u4e00\u6bb5\u7531 ChatGPT \u7ed9\u51fa\u7684\u7b80\u77ed\u7684 AOP \u6982\u5ff5\uff1a</p>\n<blockquote>\n<p>AOP \u662f\u4e00\u79cd\u7f16\u7a0b\u65b9\u6cd5\uff0c\u7528\u6765\u5c06\u5728\u7a0b\u5e8f\u4e2d\u591a\u5904\u91cd\u590d\u51fa\u73b0\u7684\u4ee3\u7801\uff08\u6bd4\u5982\u65e5\u5fd7\u3001\u6743\u9650\u63a7\u5236\uff09\u4ece\u4e3b\u8981\u4e1a\u52a1\u903b\u8f91\u4e2d\u62bd\u53d6\u51fa\u6765\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u6a21\u5757\u5316\u548c\u53ef\u7ef4\u62a4\u6027\u3002</p>\n<p>\u62bd\u53d6\u540e\u7684\u4ee3\u7801\u4f1a\u5728\u539f\u59cb\u7684\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u4e2d\u7279\u5b9a\u7684\u4f4d\u7f6e\u6267\u884c\uff0c\u8fd9\u4e9b\u4f4d\u7f6e\u7531\u5207\u70b9\uff08 Pointcut \uff09\u5b9a\u4e49\u3002\u901a\u5e38\u4f1a\u5728\u65b9\u6cd5\u6267\u884c\u524d\u3001\u6267\u884c\u540e\u3001\u629b\u51fa\u5f02\u5e38\u65f6\u7b49\u7279\u5b9a\u70b9\u6267\u884c\u62bd\u53d6\u51fa\u7684\u4ee3\u7801\uff0c\u8fd9\u4e9b\u70b9\u88ab\u79f0\u4e3a\u8fde\u63a5\u70b9\uff08 Join Point \uff09\u3002</p>\n</blockquote>\n<h2>\u6982\u8ff0</h2>\n<p>\u5728 C \u8bed\u8a00\u4e2d\uff0c\u7f16\u8bd1\u5668\u6240\u63d0\u4f9b\u7684\u7f16\u8bd1\u671f\u548c\u6267\u884c\u671f\u7684\u80fd\u529b\u76f8\u8f83\u4e8e java \u6216\u8005\u5176\u4ed6\u8bed\u8a00\u6765\u8bf4\u4f1a\u5f31\u4e00\u4e9b\uff0c\u8fd9\u4e5f\u8bb8\u5c31\u662f\u53ef\u80fd\u5f88\u5c11\u542c\u5230\u5728 C \u8bed\u8a00\u4e2d\u641e\u9762\u5411\u5207\u9762\u7f16\u7a0b\u7684\u539f\u56e0\u4e4b\u4e00\u5427\u3002</p>\n<p>\u4ece\u4e0a\u9762\u7684\u6982\u5ff5\u4e0a\u6765\u770b\uff0cAOP \u4e00\u822c\u662f\u5728\u4e00\u4e9b\u51fd\u6570\uff08\u6216\u7c7b\u65b9\u6cd5\uff09\u6267\u884c\u524d\u540e\u505a\u4e00\u4e9b\u989d\u5916\u5904\u7406\uff0c\u4f8b\u5982\u8c03\u7528\u524d\u589e\u52a0\u4e00\u4e9b\u6743\u9650\u63a7\u5236\uff0c\u8c03\u7528\u540e\u589e\u52a0\u4e00\u4e9b\u65e5\u5fd7\u8bb0\u5f55\u3002\u4ece\u8fd9\u4e9b\u884c\u4e3a\u4e0a\u6765\u8bf4\uff0c\u4efb\u4f55\u8bed\u8a00\u5176\u5b9e\u90fd\u53ef\u4ee5\u505a\u5230\u3002\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u7684\u5728\u4e00\u4e2a\u51fd\u6570\u7684\u5f00\u59cb\u52a0\u4e00\u6bb5\u903b\u8f91\u6216\u8c03\u7528\u67d0\u4e2a\u51fd\u6570\u6765\u5b9e\u73b0\u6743\u9650\u9a8c\u8bc1\uff0c\u5728\u51fd\u6570\u8fd4\u56de\u524d\u8c03\u7528\u67d0\u4e2a\u51fd\u6570\u6dfb\u52a0\u65e5\u5fd7\u7b49\u7b49\u3002\u7c7b\u4f3c\u5982\u4e0b\u4ee3\u7801\uff1a</p>\n<pre><code class=\"language-c\">void foo(void)\n{\n  if (!verify_identity())\n    return;\n\n  //...\n  \n  log(\"end\");\n}\n</code></pre>\n<p>\u4f46\u5f88\u663e\u7136\uff0c\u8fd9\u4e48\u505a\u4f1a\u5728\u7a0b\u5e8f\u7684\u5f88\u591a\u4e2a\u51fd\u6570\u4e2d\u6dfb\u52a0\u5f88\u591a\u91cd\u590d\u7684\u4ee3\u7801\uff08\u4f8b\u5982\u672c\u4f8b\u7684<code>verify_identity</code>\u548c<code>log</code>\uff09\uff0c\u4ee5\u81f3\u4e8e\u4ee3\u7801\u53d8\u5f97\u6bd4\u8f83\u81c3\u80bf\u3002</p>\n<p>\u90a3\u4e48\u6709\u6ca1\u6709\u4ec0\u4e48\u529e\u6cd5\u6765\u7626\u8eab\u5462\uff1f</p>\n<p>\u8fd9\u5c31\u662f AOP \u64c5\u957f\u7684\u9886\u57df\u4e86\u3002</p>\n<h2>\u5199\u5728\u793a\u4f8b\u4e4b\u524d</h2>\n<p>C \u8bed\u8a00\u7f16\u8bd1\u5668\u6ca1\u6709\u63d0\u4f9b\u5f88\u5b8c\u6574\u7684 AOP \u652f\u6301\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u81ea\u884c\u624b\u52a8\u5b9e\u73b0\uff0c\u6216\u8005\u4f7f\u7528\u4e00\u4e9b\u73b0\u6709\u7684\u5e93\u6765\u5b9e\u73b0\u3002</p>\n<p>\u672c\u6587\u5c06\u4f7f\u7528\u5f00\u6e90 C \u8bed\u8a00\u5e93 Melon \u7684\u51fd\u6570\u6a21\u677f\u6765\u5b9e\u73b0\u4e0a\u9762\u7684\u6548\u679c\u3002</p>\n<p>\u5728 Melon \u63d0\u4f9b\u7684\u51fd\u6570\u6a21\u677f\u7ec4\u4ef6\u4e2d\uff0c\u5b9e\u73b0\u4e86\u82e5\u5e72\u5b8f\u51fd\u6570\uff0c\u8fd9\u4e9b\u5b8f\u51fd\u6570\u90fd\u662f\u7528\u6765\u5b9a\u4e49\u4e0d\u540c\u7c7b\u578b\u7684\u51fd\u6570\u7684\u3002\u8fd9\u4e9b\u7528\u5b8f\u6765\u5b9a\u4e49\u7684\u51fd\u6570\u548c\u6211\u4eec\u539f\u751f C \u8bed\u8a00\u4e2d\u7684\u51fd\u6570\u7684\u533a\u522b\uff0c\u7b80\u5355\u6765\u8bf4\u5c31\u662f\uff0c\u5728\u6211\u4eec\u5b9e\u9645\u8981\u6267\u884c\u7684\u51fd\u6570\u903b\u8f91\u5916\uff0c\u518d\u5c01\u88c5\u4e00\u4e2a\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u4f1a\u5728\u6211\u4eec\u6307\u5b9a\u7684\u51fd\u6570\u903b\u8f91\u5f00\u59cb\u524d\u548c\u7ed3\u675f\u540e\u8c03\u7528\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\uff08\u5373\u51fd\u6570\u7684<strong>\u5165\u53e3\u56de\u8c03\u51fd\u6570</strong>\u548c<strong>\u51fa\u53e3\u56de\u8c03\u51fd\u6570</strong>\uff09\u3002</p>\n<p>\u57fa\u4e8e\u51fd\u6570\u6a21\u677f\u7684\u8fd9\u4e00\u7279\u6027\uff0cMelon \u4e2d\u5b9e\u73b0\u4e86\u4e00\u4e2a span \u7ec4\u4ef6\uff0c\u7528\u6765\u5ea6\u91cf\u4f7f\u7528\u51fd\u6570\u6a21\u677f\u5b9a\u4e49\u7684\u51fd\u6570\u7684\u65f6\u95f4\u5f00\u9500\u3002</p>\n<p>\u4f46\u5982\u679c\u4e8b\u60c5\u4ec5\u9650\u4e8e\u6b64\uff0c\u90a3\u4e48\u8fd9\u79cd AOP \u5f88\u663e\u7136\u80fd\u505a\u5230\u7684\u4e8b\u60c5\u4e5f\u57fa\u672c\u4ec5\u9650\u4e8e\u6b64\u4e86\u3002</p>\n<p>\u56e0\u6b64\uff0cMelon \u652f\u6301\u4e86 c99 \uff0c\u5e76\u5229\u7528 c99 \u63d0\u4f9b\u7684\u5b8f\u7279\u6027\uff0c\u5b9e\u73b0\u4e86\u5c06\u51fd\u6570\u6a21\u677f\u5b9a\u4e49\u7684\u51fd\u6570\u7684\u5b9e\u53c2\u4ee5\u53ef\u53d8\u53c2\u6570\u7684\u5f62\u5f0f\u4f20\u9012\u5230\u5165\u53e3\u548c\u51fa\u53e3\u56de\u8c03\u51fd\u6570\u4e2d\u3002\u8fd9\u5c31\u610f\u5473\u7740\uff0c\u5165\u53e3\u548c\u51fa\u53e3\u56de\u8c03\u51fd\u6570\u53ef\u4ee5\u8bbf\u95ee\u51fd\u6570\u7684\u53c2\u6570\uff0c\u5e76\u5bf9\u53c2\u6570\u7684\u5185\u5bb9\u4f5c\u51fa\u4fee\u6539\uff08\u4e3b\u8981\u9488\u5bf9\u6307\u9488\u6307\u5411\u7684\u5185\u5b58\u4e2d\u7684\u6570\u636e\uff09\u3002</p>\n<p>\u8fd9\u6837\uff0c\u5c31\u7ed9\u6211\u4eec\u5728\u56de\u8c03\u51fd\u6570\u4e2d\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u53ef\u64cd\u4f5c\u7a7a\u95f4\u3002\u6211\u4eec\u53ef\u4ee5\u9488\u5bf9\u4e0d\u540c\u7684\u51fd\u6570\uff0c\u4fee\u6539\u5176\u53c2\u6570\u503c\uff0c\u4ece\u800c\u6765\u5f71\u54cd\u540e\u7eed\u51fd\u6570\u8c03\u7528\u4e2d\u7684\u6267\u884c\u903b\u8f91\u3002\u4f8b\u5982\u524d\u9762\u7684\u6743\u9650\u9a8c\u8bc1\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u5927\u81f4\u7b80\u5316\u4e3a\u5982\u4e0b\u5f62\u5f0f\uff1a</p>\n<pre><code class=\"language-c\">void entry_callback(char *file, char *func, int line, ...)\n{\n  va_list args;\n  va_start(args, line);\n  int *a = (int *)va_arg(args, int *);\n  va_end(args);\n  if (!verify_identity())\n    *a = 0;\n}\n\nvoid exit_callback(char *file, char *func, int line, ...)\n{\n  va_list args;\n  va_start(args, line);\n  int *a = (int *)va_arg(args, int *);\n  va_end(args);\n  log(\"%d\\n\", *a);\n}\n\nvoid foo(int *a)\n{\n  if (!*a)\n    return;\n\n  //...\n}\n\nint bar(int *d, int e)\n{\n  if (!*d)\n    return -1;\n\n  //...\n  return 0;\n}\n</code></pre>\n<p>\u8fd9\u91cc\u7684\u4ee3\u7801\u53ea\u662f\u4e00\u4e2a\u793a\u610f\uff0c\u540e\u9762\u4f1a\u7ed9\u51fa\u4e00\u4e2a\u5b9e\u9645\u53ef\u7528\u7684\u793a\u4f8b\u3002</p>\n<p>\u6211\u4eec\u53ef\u4ee5\u968f\u610f\u589e\u52a0\u51fd\u6570\uff0c\u8fd9\u4e9b\u51fd\u6570\u90fd\u4f1a\u5229\u7528\u540c\u4e00\u5bf9\u5165\u53e3\u548c\u51fa\u53e3\u51fd\u6570\u6765\u5b9e\u73b0\u8eab\u4efd\u9a8c\u8bc1\u3002</p>\n<h2>\u793a\u4f8b</h2>\n<p>\u4e0b\u9762\u5c31\u7ed9\u51fa\u4e00\u4e2a\u53ef\u7528\u7684\u4f7f\u7528\u51fd\u6570\u6a21\u677f\u5b9e\u73b0 AOP \u7684 C \u8bed\u8a00\u4ee3\u7801\u3002</p>\n<pre><code class=\"language-c\">//a.c\n\n#include \"mln_func.h\"\n#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n#include &lt;stdarg.h&gt;\n\nMLN_FUNC_VOID(static, void, foo, (int *a, int b), (a, b), {\n    printf(\"in %s: %d\\n\", __FUNCTION__, *a);\n    *a += b;\n})\n\nMLN_FUNC(static, int, bar, (void), (), {\n    printf(\"%s\\n\", __FUNCTION__);\n    return 0;\n})\n\nstatic void my_entry(const char *file, const char *func, int line, ...)\n{\n    if (strcmp(func, \"foo\"))\n        return;\n\n    va_list args;\n    va_start(args, line);\n    int *a = (int *)va_arg(args, int *);\n    va_end(args);\n\n    printf(\"entry %s %s %d %d\\n\", file, func, line, *a);\n    ++(*a);\n}\n\nstatic void my_exit(const char *file, const char *func, int line, ...)\n{\n    if (strcmp(func, \"foo\"))\n        return;\n\n    va_list args;\n    va_start(args, line);\n    int *a = (int *)va_arg(args, int *);\n    va_end(args);\n\n    printf(\"exit %s %s %d %d\\n\", file, func, line, *a);\n}\n\nint main(void)\n{\n    int a = 1;\n\n    mln_func_entry_callback_set(my_entry);\n    mln_func_exit_callback_set(my_exit);\n\n    foo(&amp;a, 2);\n    return bar();\n}\n</code></pre>\n<p>\u8fd9\u6bb5\u51fd\u6570\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>MLN_FUNC</code>\u548c<code>MLN_FUNC_VOID</code>\u6765\u5b9a\u4e49\u4e86\u4e24\u4e2a\u51fd\u6570\uff0c\u5373<code>foo</code>\u548c<code>bar</code>\u3002\u4e24\u4e2a\u51fd\u6570\u7684\u903b\u8f91\u5f88\u7b80\u5355\uff0c\u5c31\u662f printf \u8f93\u51fa\u5f53\u524d\u51fd\u6570\u540d\u4ee5\u53ca\u53c2\u6570\u503c\uff08\u5982\u679c\u6709\u53c2\u6570\u7684\u8bdd\uff09\u3002\u540c\u65f6\uff0c\u6211\u4eec\u4e5f\u4f7f\u7528\u4e86<code>mln_func_entry_callback_set</code>\u548c<code>mln_func_exit_callback_set</code>\u5b9a\u4e49\u4e86\u4e24\u4e2a\u5168\u5c40\u56de\u8c03\u51fd\u6570\uff0c\u7528\u6765\u5728\u51fd\u6570\u8c03\u7528\u5f00\u59cb\u548c\u7ed3\u675f\u65f6\u8c03\u7528\u3002</p>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u56de\u8c03\u51fd\u6570\u4e2d\u4f7f\u7528<code>strcmp</code>\u5bf9\u8fdb\u5165\u56de\u8c03\u7684\u51fd\u6570\u505a\u4e86\u8fc7\u6ee4\uff0c\u4ec5\u5bf9<code>foo</code>\u51fd\u6570\u505a\u989d\u5916\u5904\u7406\u3002\u5728\u5165\u53e3\u56de\u8c03\u4e2d\u8f93\u51fa\u51fd\u6570\u4fe1\u606f\u53ca\u7b2c\u4e00\u4e2a\u53c2\u6570\u7684\u503c\uff0c\u968f\u540e\u4fee\u6539\u53c2\u6570\u6307\u9488\u6307\u5411\u7684\u5185\u5b58\u4e2d\u7684\u503c\u3002\u5728\u51fa\u53e3\u56de\u8c03\u4e2d\u8f93\u51fa\u51fd\u6570\u4fe1\u606f\u548c\u53c2\u6570\u503c\u3002</p>\n<p>\u6211\u4eec\u6765\u7f16\u8bd1\u4e00\u4e0b\uff08\u6211\u4eec\u5047\u5b9a\u8fd9\u4e2a\u4ee3\u7801\u6587\u4ef6\u540d\u4e3a<code>a.c</code>\uff09\uff1a</p>\n<pre><code class=\"language-bash\">cc -o a a.c -I /usr/local/melon/include/ -L /usr/local/melon/lib/ -lmelon -std=c99 -DMLN_C99 -DMLN_FUNC_FLAG\n</code></pre>\n<p>\u8fd9\u91cc\uff1a</p>\n<ul>\n<li><code>/usr/local/melon</code>\u662f Melon \u5e93\u7684\u9ed8\u8ba4\u5b89\u88c5\u8def\u5f84\u3002</li>\n<li><code>-std=c99</code>\u662f\u542f\u7528 c99 \u3002</li>\n<li><code>-DMLN_C99</code>\u662f\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3a<code>MLN_C99</code>\u7684\u5b8f\uff0c\u8fd9\u4e2a\u5b8f\u7528\u6765\u542f\u7528\u51fd\u6570\u6a21\u677f\u7ec4\u4ef6\u4e2d C99 \u4e0b\u624d\u6709\u7684\u7279\u6027\u3002</li>\n<li><code>-DMLN_FUNC_FLAG</code>\u7528\u6765\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3a<code>MLN_FUNC_FLAG</code>\u7684\u5b8f\uff0c\u8fd9\u4e2a\u5b8f\u7528\u6765\u542f\u7528\u51fd\u6570\u6a21\u677f\u529f\u80fd\u3002\u662f\u7684\uff0c\u5982\u679c\u6ca1\u6709\u8fd9\u4e2a\u5b8f\uff0c\u4e0a\u9762\u7684\u90a3\u4e9b\u4f7f\u7528<code>MLN_FUNC</code>\u5b9a\u4e49\u7684\u51fd\u6570\u5c31\u662f\u666e\u901a\u7684 C \u8bed\u8a00\u51fd\u6570\uff0c\u4e5f\u4e0d\u4f1a\u89e6\u53d1\u5165\u53e3\u548c\u51fa\u53e3\u56de\u8c03\u51fd\u6570\u7684\u8c03\u7528\u3002</li>\n</ul>\n<p>\u6267\u884c\u4e00\u4e0b\u770b\u770b\u6548\u679c\uff1a</p>\n<pre><code>entry a.c foo 6 1\nin __mln_func_foo: 2\nexit a.c foo 6 4\n__mln_func_bar\n</code></pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff1a</p>\n<ul>\n<li>\u5165\u53e3\u56de\u8c03\u51fd\u6570\u4e2d\uff0cfoo \u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u6307\u5411\u7684\u5185\u5b58\u4e2d\u7684\u503c\u4e3a<code>1</code>\u3002</li>\n<li>\u8fdb\u5165<code>foo</code>\u7684\u5b9e\u9645\u51fd\u6570\u903b\u8f91\u4e2d\uff0cprintf \u8f93\u51fa\u5f53\u524d\u7684\u51fd\u6570\u540d\u4e3a<code>__mln_func_foo</code>\uff0c\u4ee5\u53ca\u6b64\u65f6\u770b\u5230\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u7684\u503c\u4e3a<code>2</code>\uff0c\u4e0d\u518d\u662f<code>1</code>\u4e86\uff0c\u56e0\u4e3a\u5728\u5165\u53e3\u56de\u8c03\u51fd\u6570\u4e2d\u88ab\u4fee\u6539\u4e86\u3002<code>__mln_func_foo</code>\u8fd9\u4e2a\u51fd\u6570\u6267\u884c\u7684\u624d\u662f\u6211\u4eec\u5b9a\u4e49\u7684\u903b\u8f91\uff0c\u800c<code>foo</code>\u662f\u5bf9<code>__mln_func_foo</code>\u7684\u4e00\u4e2a\u5c01\u88c5\u3002</li>\n<li>\u51fa\u53e3\u56de\u8c03\u51fd\u6570\u4e2d\uff0c\u6211\u4eec\u770b\u5230\u7b2c\u4e00\u4e2a\u53c2\u6570\u7684\u503c\u53d8\u4e3a\u4e86<code>4</code>\uff0c\u56e0\u4e3a\u5b83\u5728\u6211\u4eec\u7ed9\u51fa\u7684\u51fd\u6570\u903b\u8f91\u4e2d\u505a\u4e86\u4fee\u6539\u3002</li>\n<li>\u6700\u540e\u8f93\u51fa\u7684\u662f<code>bar</code>\u7684\u5b9e\u9645\u6267\u884c\u903b\u8f91\u6240\u5728\u7684\u51fd\u6570\u540d\uff0c\u4e0e<code>foo</code>\u7684\u5f62\u5f0f\u4e00\u81f4\u3002</li>\n</ul>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u53bb\u6389<code>MLN_FUNC_FLAG</code>\u8fd9\u4e2a\u5b8f\u518d\u6b21\u7f16\u8bd1\u4e00\u6b21\uff1a</p>\n<pre><code class=\"language-bash\">cc -o a a.c -I /usr/local/melon/include/ -L /usr/local/melon/lib/ -lmelon -std=c99 -DMLN_C99\n</code></pre>\n<p>\u7136\u540e\u6267\u884c\u4e00\u4e0b\u770b\u770b\u8f93\u51fa\u7ed3\u679c\uff1a</p>\n<pre><code>in foo: 1\nbar\n</code></pre>\n<p>\u53ef\u4ee5\u770b\u5f97\u51fa\uff0c\u6b64\u65f6<code>foo</code>\u548c<code>bar</code>\u4e0d\u518d\u662f\u5c01\u88c5\u51fd\u6570\uff0c\u800c\u662f\u6211\u4eec\u5b9a\u4e49\u7684\u51fd\u6570\u903b\u8f91\u7684\u51fd\u6570\u540d\uff0c\u5373\u666e\u901a\u7684 C \u8bed\u8a00\u51fd\u6570\u3002</p>\n<p>\u8bfb\u5230\u8fd9\u91cc\u7684\u90fd\u662f\u771f\u7231\uff0c\u611f\u8c22\u9605\u8bfb\uff01</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/cnbatch", 
        "name": "cnbatch", 
        "avatar": "https://cdn.v2ex.com/gravatar/7eb06cdf719fb364a1dfbbaefc4f9d36?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1017363", 
      "title": "\u7f51\u7edc\u8bed\u8a00\u6c61\u67d3/\u626d\u66f2\u4e13\u4e1a\u672f\u8bed\u540d\u8bcd\u2014\u2014\u300a\u4e3a\u4ec0\u4e48 c \u8bed\u8a00\u8fd9\u4e48\u62bd\u8c61?\u300b", 
      "id": "https://www.v2ex.com/t/1017363", 
      "date_published": "2024-02-21T14:04:14+00:00", 
      "content_html": "<p>\u77e5\u4e4e\u4e0a\u6709\u4eba\u53d1\u4e86\u4e2a\u63d0\u95ee\uff0c\u300a\u4e3a\u4ec0\u4e48 c \u8bed\u8a00\u8fd9\u4e48\u62bd\u8c61?\u300b<br/>\n\u63d0\u95ee\u8005\u89c9\u5f97\u4f4d\u8fd0\u7b97\u201c\u62bd\u8c61\u201d\uff1a<br/>\n<a href=\"https://www.zhihu.com/question/627863026\" rel=\"nofollow\">https://www.zhihu.com/question/627863026</a></p>\n<p>\u4e00\u5f00\u59cb\u6211\u5b9e\u5728\u662f\u83ab\u540d\u5176\u5999\uff0c\u4f4d\u8fd0\u7b97\u8fd9\u4e48\u7b80\u5355\u5177\u4f53\u7684\u64cd\u4f5c\uff0c\u54ea\u6765\u7684\u201c\u62bd\u8c61\u201d\uff1f</p>\n<p>\u7136\u540e\u518d\u770b\u8bc4\u8bba\u533a\u3001\u56de\u7b54\u533a\uff0c\u624d\u660e\u767d\u539f\u6765\u63d0\u95ee\u4eba\u7684\u201c\u62bd\u8c61\u201d\u7adf\u7136\u662f\u7f51\u7edc\u8bed\u8a00\u7684\u8bed\u5883\uff0c\u800c\u4e0d\u662f\u4e13\u4e1a\u672f\u8bed\u7684\u8bed\u5883\u3002</p>\n<p>\u8fd9\u6b21\u201c\u62bd\u8c61\u201d\u4e8c\u5b57\u7684\u7528\u6cd5\u53ef\u771f\u591f\u62bd\u8c61\u7684\u3002<br/>\uff08\u4e25\u8c28\u7684\u5907\u6ce8\uff1a\u6700\u540e\u4e00\u4e2a\u201c\u62bd\u8c61\u201d\u662f\u7f51\u7edc\u7528\u8bed\uff09</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/monkeyNik", 
        "name": "monkeyNik", 
        "avatar": "https://cdn.v2ex.com/avatar/d196/0d1a/499929_large.png?m=1697247708"
      }, 
      "url": "https://www.v2ex.com/t/1012060", 
      "title": "C \u8bed\u8a00\u51fd\u6570\u8d44\u6e90\u5f00\u9500\u53ef\u89c2\u6d4b\u6027", 
      "id": "https://www.v2ex.com/t/1012060", 
      "date_published": "2024-01-27T08:52:08+00:00", 
      "content_html": "<p>\u4e4b\u524d\u7684\u6587\u7ae0\u63d0\u53ca\u8fc7\u5f00\u6e90 C \u8bed\u8a00\u5e93<a href=\"https://github.com/Water-Melon/Melon\" rel=\"nofollow\">Melon</a>\u7684<a href=\"http://doc.melonc.io/cn/func.html\" rel=\"nofollow\">\u51fd\u6570\u6a21\u677f</a>\u3002\u4f7f\u7528\u51fd\u6570\u6a21\u677f\u6765\u6269\u5c55\u51fd\u6570\u529f\u80fd\u3002</p>\n<p>\u4eca\u5929\uff0c\u6211\u4eec\u4ecb\u7ecd Melon \u4e2d\u7684<a href=\"http://doc.melonc.io/cn/span.html\" rel=\"nofollow\">span</a>\u7ec4\u4ef6\uff0c\u4f7f\u7528\u5b83\u6765\u8f7b\u677e\u76d1\u63a7\u51fd\u6570\u7684\u8c03\u7528\u8017\u65f6\u60c5\u51b5\u3002</p>\n<h2>\u6982\u8ff0</h2>\n<p>Melon \u4e2d\u7684\u8d44\u6e90\u5f00\u9500\uff08 span \uff09\u7ec4\u4ef6\u662f\u7528\u6765\u6d4b\u91cf C \u8bed\u8a00\u51fd\u6570\u5f00\u9500\u7684\uff0c\u8fd9\u4e2a\u6a21\u5757\u9700\u8981\u914d\u5408<code>\u51fd\u6570\u6a21\u677f</code>\u6a21\u5757\u4e00\u540c\u4f7f\u7528\uff0c\u56e0\u6b64\u4e5f\u9700\u8981\u5b9a\u4e49<code>MLN_FUNC_FLAG</code>\u624d\u4f1a\u4f7f\u5f97\u51fd\u6570\u6a21\u677f\u529f\u80fd\u542f\u7528\uff0c\u8fdb\u800c\u5b9e\u73b0\u51fd\u6570\u5f00\u9500\u7684\u8ddf\u8e2a\u3002</p>\n<p>\u76ee\u524d\u652f\u6301\u7684\u5f00\u9500\u5982\u4e0b\uff1a</p>\n<ul>\n<li>\u65f6\u95f4\u5f00\u9500</li>\n</ul>\n<h2>\u5934\u6587\u4ef6</h2>\n<pre><code class=\"language-c\">#include \"mln_span.h\"\n</code></pre>\n<h2>\u6a21\u5757\u540d</h2>\n<p><code>span</code></p>\n<p>\u5728 Melon \u4e2d\u652f\u6301\u6a21\u5757\u9009\u62e9\u6027\u7f16\u8bd1\uff0c\u56e0\u6b64\u53ef\u4ee5\u9009\u62e9\u6307\u5b9a\u7684\u6a21\u5757\u8fdb\u884c\u7f16\u8bd1\uff0c\u811a\u672c\u5c06\u81ea\u884c\u8ba1\u7b97\u8be5\u6a21\u5757\u6240\u4f9d\u8d56\u7684 Melon \u4e2d\u7684\u5176\u4ed6\u6a21\u5757\u5e76\u4e00\u540c\u8fdb\u884c\u7f16\u8bd1\u3002</p>\n<h2>\u793a\u4f8b</h2>\n<p>\u4e0b\u9762\u6211\u4eec\u4e00\u8d77\u770b\u4e00\u4e2a\u591a\u7ebf\u7a0b\u7684\u793a\u4f8b\uff0c\u7528\u6765\u5c55\u793a<code>mln_span</code>\u63a5\u53e3\u7684\u4f7f\u7528\u4ee5\u53ca\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u7684\u6548\u679c\u3002</p>\n<pre><code class=\"language-c\">//a.c\n\n#include &lt;pthread.h&gt;\n#include \"mln_span.h\"\n#include \"mln_func.h\"\n\nMLN_FUNC(int, abc, (int a, int b), (a, b), {\n    return a + b;\n})\n\nMLN_FUNC(static int, bcd, (int a, int b), (a, b), {\n    return abc(a, b) + abc(a, b);\n})\n\nMLN_FUNC(static int, cde, (int a, int b), (a, b), {\n    return bcd(a, b) + bcd(a, b);\n})\n\nvoid *pentry(void *args)\n{\n    int i;\n    mln_span_start();\n    for (i = 0; i &lt; 10; ++i) {\n        cde(i, i + 1);\n    }\n\n    mln_span_stop();\n    mln_span_dump();\n    mln_span_release();\n    return NULL;\n}\n\nint main(void)\n{\n    int i;\n    pthread_t pth;\n\n\n    pthread_create(&amp;pth, NULL, pentry, NULL);\n\n    for (i = 0; i &lt; 10; ++i) {\n        bcd(i, i + 1);\n    }\n\n    pthread_join(pth, NULL);\n\n    return 0;\n}\n</code></pre>\n<p>\u524d\u9762\u6211\u4eec\u8bf4\u8fc7\uff0cspan \u7ec4\u4ef6\u9700\u8981\u914d\u5408\u51fd\u6570\u6a21\u677f\u7ec4\u4ef6\u4e00\u540c\u4f7f\u7528\u3002\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u51fd\u6570\u6a21\u677f\u7ec4\u4ef6\u5b9a\u4e49\u4e86\u4e09\u4e2a\u51fd\u6570<code>abc</code>, <code>bcd</code>, <code>cde</code>\u3002</p>\n<p>\u7136\u540e\u6211\u4eec\u5728<code>main</code>\u51fd\u6570\u4e2d\u542f\u52a8\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u5e76\u5728\u7ebf\u7a0b\u5165\u53e3\u51fd\u6570\u5185\uff0c\u8c03\u7528<code>mln_span_start</code>\u5f00\u542f\u8d44\u6e90\u6d88\u8017\u8ddf\u8e2a\u3002\u7136\u540e\u8c03\u7528<code>cde</code>\u51fd\u6570\u5341\u6b21\u3002\u800c\u5728<code>main</code>\u51fd\u6570\u4e2d\uff0c\u5728\u521b\u5efa\u7ebf\u7a0b\u540e\uff0c\u5faa\u73af\u8c03\u7528<code>bcd</code>\u51fd\u6570\u5341\u6b21\uff0c\u6700\u540e\u7b49\u5f85\u7ebf\u7a0b\u9000\u51fa\uff0c\u7a0b\u5e8f\u7ed3\u675f\u3002</p>\n<p>\u6211\u4eec\u5bf9\u8fd9\u6bb5\u7a0b\u5e8f\u8fdb\u884c\u7f16\u8bd1\uff1a</p>\n<pre><code class=\"language-bash\">cc -o a a.c -I /usr/local/melon/include/ -L /usr/local/melon/lib/ -lmelon -DMLN_FUNC_FLAG -lpthread\n</code></pre>\n<p>\u6ce8\u610f\uff0c\u8fd9\u91cc<code>-DMLN_FUNC_FLAG</code>\u662f\u7528\u6765\u542f\u7528\u51fd\u6570\u6a21\u677f\u6a21\u5757\u7684\u529f\u80fd\u3002\u5982\u679c\u4e0d\u5b9a\u4e49\u8fd9\u4e2a\u5b8f\uff0c\u90a3\u4e48\u4f7f\u7528<code>MLN_FUNC</code>\u5b9a\u4e49\u7684\u51fd\u6570\u5c31\u662f\u666e\u901a C \u8bed\u8a00\u51fd\u6570\uff0c\u4e0d\u4f1a\u542f\u7528\u4efb\u4f55\u8ddf\u8e2a\u80fd\u529b\u3002</p>\n<p>\u7f16\u8bd1\u597d\u540e\u8fd0\u884c\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u770b\u5230\u7c7b\u4f3c\u5982\u4e0b\u7684\u8f93\u51fa\uff1a</p>\n<pre><code>| pentry at a.c:20 takes 92 (us)\n  | cde at a.c:13 takes 4 (us)\n    | bcd at a.c:9 takes 1 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n    | bcd at a.c:9 takes 1 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n  | cde at a.c:13 takes 5 (us)\n    | bcd at a.c:9 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n    | bcd at a.c:9 takes 2 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n  | cde at a.c:13 takes 24 (us)\n    | bcd at a.c:9 takes 1 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n    | bcd at a.c:9 takes 21 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n  | cde at a.c:13 takes 5 (us)\n    | bcd at a.c:9 takes 1 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n    | bcd at a.c:9 takes 1 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n  | cde at a.c:13 takes 3 (us)\n    | bcd at a.c:9 takes 2 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n    | bcd at a.c:9 takes 1 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n  | cde at a.c:13 takes 30 (us)\n    | bcd at a.c:9 takes 24 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 1 (us)\n    | bcd at a.c:9 takes 6 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n  | cde at a.c:13 takes 3 (us)\n    | bcd at a.c:9 takes 2 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n    | bcd at a.c:9 takes 1 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n  | cde at a.c:13 takes 3 (us)\n    | bcd at a.c:9 takes 2 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 1 (us)\n    | bcd at a.c:9 takes 1 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n  | cde at a.c:13 takes 7 (us)\n    | bcd at a.c:9 takes 1 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n    | bcd at a.c:9 takes 2 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 1 (us)\n  | cde at a.c:13 takes 3 (us)\n    | bcd at a.c:9 takes 2 (us)\n      | abc at a.c:5 takes 1 (us)\n      | abc at a.c:5 takes 0 (us)\n    | bcd at a.c:9 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n      | abc at a.c:5 takes 0 (us)\n</code></pre>\n<h2>\u6700\u540e</h2>\n<p>\u611f\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u6b22\u8fce\u8bbf\u95ee<a href=\"https://github.com/Water-Melon/Melon\" rel=\"nofollow\">Melon \u7684 Github</a>\u8fdb\u884c\u8bd5\u7528\u3002Melon \u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684 C \u8bed\u8a00\u5e93\uff0c\u5185\u542b\u591a\u79cd\u6570\u636e\u7ed3\u6784\u3001\u7b97\u6cd5\u548c\u5e38\u7528\u7ec4\u4ef6\u3002Melon \u5e76\u4e0d\u662f\u4e00\u4e2a\u7eaf\u7cb9\u7684\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u5e93\uff0c\u800c\u662f\u81f4\u529b\u4e8e\u63d0\u4f9b\u5f00\u53d1\u4e2d\u5e38\u7528\u7684\u7ec4\u4ef6\uff0c\u5982\uff1a\u5185\u5b58\u6c60\u3001\u7ebf\u7a0b\u6c60\u3001\u591a\u8fdb\u7a0b\u6846\u67b6\u3001\u53ef\u89c2\u6d4b\u6027\u7b49\u3002Melon \u63d0\u4f9b\u4e2d\u82f1\u6587\u6587\u6863\uff0c\u5185\u542b\u5404\u6a21\u5757\u63a5\u53e3\u8bf4\u660e\u548c\u793a\u4f8b\u4ee3\u7801\uff0c\u4fbf\u4e8e\u5f00\u53d1\u8005\u5feb\u901f\u4e0a\u624b\u3002</p>\n<p>\u611f\u8c22\u9605\u8bfb\uff01</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/monkeyNik", 
        "name": "monkeyNik", 
        "avatar": "https://cdn.v2ex.com/avatar/d196/0d1a/499929_large.png?m=1697247708"
      }, 
      "url": "https://www.v2ex.com/t/1010847", 
      "title": "C \u8bed\u8a00\u7528\u6237\u6001\u51fd\u6570\u53ef\u89c2\u6d4b\u6027", 
      "id": "https://www.v2ex.com/t/1010847", 
      "date_published": "2024-01-23T04:08:57+00:00", 
      "content_html": "<p>\u672c\u6587\u4e0d\u662f\u4ecb\u7ecd eBPF \u76f8\u5173\u7684\u7528\u6237\u6001 Probe \u7684\u5185\u5bb9\uff0c\u800c\u662f\u5982\u4f55\u5229\u7528\u5f00\u6e90 C \u8bed\u8a00\u5e93<a href=\"https://github.com/Water-Melon/Melon\" rel=\"nofollow\">Melon</a>\u7684\u51fd\u6570\u6a21\u677f\u6765\u8f7b\u677e\u5b9e\u73b0\u51fd\u6570\u7684\u53ef\u89c2\u6d4b\u6027\u9700\u6c42\uff0c\u4f8b\u5982\uff1a\u6d4b\u91cf\u8017\u65f6\u7b49\u3002</p>\n<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u7684\u662f Melon \u5e93\u4e2d\u7684<code>func</code>\u6a21\u5757\uff0c\u4e4b\u6240\u4ee5\u6ca1\u6709\u7ed9\u8fd9\u4e2a\u6a21\u5757\u8d77\u540d\u53eb\u53ef\u89c2\u6d4b\u6027\u6216\u8005<code>span</code>\uff0c\u539f\u56e0\u662f\u8fd9\u662f\u4e00\u4e2a\u66f4\u4e3a\u901a\u7528\u7684\u6a21\u5757\uff0c\u4e0d\u4ec5\u9650\u4e8e\u53ef\u89c2\u6d4b\u6027\u7684\u9700\u6c42\u3002</p>\n<p><strong><code>func</code>\u6a21\u5757\u5b9e\u73b0\u7684\u529f\u80fd\u4e0e GCC \u7684 constructor \u548c destructor \u7279\u6027\u5341\u5206\u76f8\u4f3c\uff0c\u5c31\u662f\u5728 C \u8bed\u8a00\u51fd\u6570\u7684\u5165\u53e3\u548c\u51fa\u53e3\u589e\u52a0\u7528\u6237\u81ea\u5b9a\u4e49\u56de\u8c03\u51fd\u6570\uff0c\u5728\u8c03\u7528\u51fd\u6570\u65f6\u81ea\u884c\u8c03\u7528\u8fd9\u4e9b\u51fd\u6570\u3002</strong></p>\n<p>\u6211\u4eec\u5148\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a</p>\n<pre><code class=\"language-c\">// a.c\n\n#include \"mln_func.h\"\n\nMLN_FUNC(int, abc, (int a, int b), (a, b), {\n    printf(\"in %s\\n\", __FUNCTION__);\n    return a + b;\n})\n\nMLN_FUNC(static int, bcd, (int a, int b), (a, b), {\n    printf(\"in %s\\n\", __FUNCTION__);\n    return abc(a, b) + abc(a, b);\n})\n\nstatic void my_entry(const char *file, const char *func, int line)\n{\n    printf(\"entry %s %s %d\\n\", file, func, line);\n}\n\nstatic void my_exit(const char *file, const char *func, int line)\n{\n    printf(\"exit %s %s %d\\n\", file, func, line);\n}\n\n\nint main(void)\n{\n    mln_func_entry_callback_set(my_entry);\n    mln_func_exit_callback_set(my_exit);\n    printf(\"%d\\n\", bcd(1, 2));\n    return 0;\n}\n</code></pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u4f7f\u7528<code>MLN_FUNC</code>\u5b9a\u4e49\u4e86\u4e24\u4e2a\u51fd\u6570\uff0c\u5206\u522b\u4e3a<code>abc</code>\u548c<code>bcd</code>\uff0c\u4e14\u5728<code>bcd</code>\u4e2d\u4f1a\u8c03\u7528<code>abc</code>\u3002\u5176\u5b9e\u8fd9\u4e2a\u6a21\u677f\u5b8f\u76f8\u5bf9\u6bd4\u8f83\u5bb9\u6613\u7406\u89e3\uff0c\u5176\u5b8f\u51fd\u6570\u53c2\u6570\u987a\u5e8f\u5982\u4e0b\uff1a</p>\n<ul>\n<li>\u8fd4\u56de\u503c\u7c7b\u578b\uff08\u6db5\u76d6\u51fd\u6570\u4f5c\u7528\u57df\uff0c\u5982<code>static</code>\uff09</li>\n<li>\u51fd\u6570\u540d</li>\n<li>\u51fd\u6570\u5f62\u53c2\u5217\u8868\uff08\u9700\u8981\u7528<code>()</code>\u6269\u4f4f\uff09</li>\n<li>\u51fd\u6570\u5b9e\u53c2\u5217\u8868\uff08\u9700\u8981\u7528<code>()</code>\u6269\u4f4f\uff09</li>\n<li>\u51fd\u6570\u4f53</li>\n</ul>\n<p>\u8fd9\u91cc\u552f\u4e00\u6709\u4e9b\u56f0\u60d1\u7684\u662f\u5b9e\u53c2\u5217\u8868\uff0c\u8fd9\u4e0e\u5b8f\u7684\u5b9e\u73b0\u6709\u5173\u3002\u6211\u4eec\u4ee5<code>abc</code>\u4e3a\u4f8b\uff0c\u7b80\u8ff0\u4e00\u4e0b\u5b9e\u73b0\u539f\u7406\u3002</p>\n<p><strong>\u539f\u7406\uff1a</strong>\u8fd9\u4e2a\u5b8f\u4f1a\u5b9a\u4e49\u4e24\u4e2a\u51fd\u6570\uff0c\u4e00\u4e2a\u540d\u4e3a<code>abc</code>\uff0c\u4e00\u4e2a\u540d\u4e3a<code>__abc</code>\u3002\u51fd\u6570\u4f53\u5176\u5b9e\u5bf9\u5e94\u7684\u662f<code>__abc</code>\uff0c\u4e5f\u5c31\u662f\u8bf4<code>__abc</code>\u624d\u662f\u771f\u6b63\u6211\u4eec\u671f\u671b\u8c03\u7528\u7684\u90a3\u4e2a\u51fd\u6570\uff0c\u800c<code>abc</code>\u662f\u5bf9<code>__abc</code>\u7684\u4e00\u4e2a\u5c01\u88c5\uff0c\u4f1a\u5728<code>__abc</code>\u7684\u8c03\u7528\u524d\u540e\u8c03\u7528\u81ea\u5b9a\u4e49\u56de\u8c03\u51fd\u6570\u3002</p>\n<p>\u800c\u5b9e\u53c2\u5217\u8868\u5c31\u662f\u5728\u51fd\u6570<code>abc</code>\u4e2d\u8c03\u7528<code>__abc</code>\u65f6\u9700\u8981\u7ed9<code>__abc</code>\u4f20\u9012\u7684\u53c2\u6570\uff0c\u6240\u4ee5\u8fd9\u4e2a\u53c2\u6570\u5217\u8868\u5176\u5b9e\u5c31\u662f\u5f62\u53c2\u5217\u8868\u53bb\u6389\u7c7b\u578b\u4e4b\u540e\u7684\u540d\u5b57\u548c\u987a\u5e8f\u3002</p>\n<blockquote>\n<p>\u8fd9\u4e2a\u5b9e\u53c2\u5217\u8868\u65e0\u6cd5\u5ffd\u7565\uff0c\u662f\u56e0\u4e3a<code>__abc</code>\u4e0d\u80fd\u7701\u7565\uff0c\u800c<code>__abc</code>\u4e0d\u80fd\u7701\u7565\u662f\u56e0\u4e3a\u51fd\u6570\u4f53\u4e2d\u53ef\u80fd\u5305\u542b return \u8bed\u53e5\uff0c\u56e0\u6b64\u6211\u4eec\u65e0\u6cd5\u5b8c\u5168\u9690\u5f0f\u5730\u5728 return \u524d\uff0c\u751a\u81f3\u662f\u5728 return \u7684\u8868\u8fbe\u5f0f\u8ba1\u7b97\u540e\u771f\u6b63\u7684\u8fd4\u56de\u524d\u8c03\u7528\u56de\u8c03\u51fd\u6570\u3002\u6240\u4ee5\u5fc5\u987b\u5355\u72ec\u5b9a\u4e49\u6210\u4e00\u4e2a\u51fd\u6570\u4e5f\u5c31\u662f<code>__abc</code>\u3002</p>\n</blockquote>\n<p>\u4e0b\u9762\u6211\u4eec\u6765\u7f16\u8bd1\u8fd9\u4e2a\u7a0b\u5e8f\uff1a</p>\n<pre><code class=\"language-bash\">cc -o a a.c -I /path/to/melon/include -L /path/to/melon/lib -lmelon\n</code></pre>\n<p>\u5176\u4e2d<code>/path/to/melon</code>\u7684\u90e8\u5206\u662f Melon \u7684\u5b89\u88c5\u8def\u5f84\uff0c\u9ed8\u8ba4\u4e00\u822c\u662f<code>/usr/local/melon</code>\u3002</p>\n<p>\u7136\u540e\u8fd0\u884c\u4e00\u4e0b</p>\n<pre><code class=\"language-c\">./a\n\nin bcd\nin abc\nin abc\n6\n</code></pre>\n<p>\u4f60\u4f1a\u53d1\u73b0\u56de\u8c03\u51fd\u6570\u5b8c\u5168\u6ca1\u88ab\u8c03\u7528\u3002\u8fd9\u4e0d\u662f\u6211\u4eec\u7684\u4ee3\u7801\u6709\u95ee\u9898\uff0c\u800c\u662f\u6211\u4eec\u5e76\u672a\u542f\u7528\u6a21\u677f\u529f\u80fd\u3002\u6a21\u677f\u542f\u7528\u9700\u8981\u7f16\u8bd1\u65f6\u5b58\u5728<code>MLN_FUNC_FLAG</code>\u7684\u5b8f\u5b9a\u4e49\uff0c\u6211\u4eec\u65e2\u53ef\u4ee5\u5c06\u5b83\u5b9a\u4e49\u5728\u6e90\u6587\u4ef6\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u5728\u7f16\u8bd1\u65f6\u4f5c\u4e3a\u547d\u4ee4\u884c\u53c2\u6570\u7ed9\u51fa\u3002\u4e0b\u9762\u6211\u4ee5\u540e\u8005\u4e3a\u4f8b\u5c55\u793a\uff1a</p>\n<pre><code>cc -o a a.c -I /path/to/melon/include -L /path/to/melon/lib -lmelon -DMLN_FUNC_FLAG\n</code></pre>\n<p>\u518d\u6b21\u8fd0\u884c</p>\n<pre><code>./a\n\nentry a.c bcd 10\nin __bcd\nentry a.c abc 5\nin __abc\nexit a.c abc 5\nentry a.c abc 5\nin __abc\nexit a.c abc 5\nexit a.c bcd 10\n6\n</code></pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u56de\u8c03\u51fd\u6570\u90fd\u88ab\u6b63\u5e38\u8c03\u7528\u4e86\u3002</p>\n<p><strong>\u5229\u7528\u8fd9\u4e2a\u5f00\u5173\u5b8f\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u4e0d\u4fee\u6539\u4efb\u4f55\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\uff0c\u8f7b\u677e\u5207\u6362\u662f\u5426\u9700\u8981\u5f00\u542f\u8fd9\u9879\u529f\u80fd\u3002</strong></p>\n<h2>\u7efc\u5408\u793a\u4f8b</h2>\n<p>\u524d\u9762\u7ed9\u51fa\u7684\u4f8b\u5b50\u6bd4\u8f83\u7b80\u5355\uff0c\u90a3\u4e48\u4e0b\u9762\u5c31\u6765\u770b\u4e00\u4e2a\u5b9e\u73b0\u6d4b\u91cf\u51fd\u6570\u8c03\u7528\u8017\u65f6\u7684\u4f8b\u5b50\u5427\u3002</p>\n<p>\u8fd9\u91cc\u6211\u5c06\u7ed9\u51fa\u4e09\u4e2a\u6587\u4ef6\uff1a</p>\n<ul>\n<li><code>span.h</code>\uff1a\u8fd9\u662f\u4e3a\u6d4b\u91cf\u8017\u65f6\u6240\u5b9a\u4e49\u7684\u6570\u636e\u7ed3\u6784\u548c\u51fd\u6570\u58f0\u660e\u7b49\u5185\u5bb9\u3002</li>\n<li><code>span.c</code>\uff1a\u8fd9\u662f\u4e3a\u6d4b\u91cf\u8017\u65f6\u5b9a\u4e49\u7684\u76f8\u5173\u51fd\u6570\u3002</li>\n<li><code>a.c</code>\uff1a\u8fd9\u662f\u6211\u4eec\u81ea\u5b9a\u4e49\u7684\u4e00\u4e9b\u51fd\u6570\u4ee5\u53ca\u5728<code>main</code>\u51fd\u6570\u4e2d\u8c03\u7528\u8fd9\u4e9b\u51fd\u6570\u3002</li>\n</ul>\n<p>\u5176\u4e2d\uff0c<code>span.h</code>\u548c<code>span.c</code>\u53ef\u4ee5\u968f\u610f\u590d\u5236\u7c98\u8d34\u4f7f\u7528\uff0c\u8fd9\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u6a21\u5757\uff0c\u5f53\u7136\uff0c\u4f60\u8fd8\u9700\u8981\u5148\u5b89\u88c5\u597d Melon \u5e93\u3002</p>\n<h4>span.h</h4>\n<pre><code class=\"language-c\">#include &lt;sys/time.h&gt;\n#include \"mln_array.h\"\n\ntypedef struct mln_span_s {\n    struct timeval     begin;\n    struct timeval     end;\n    const char        *file;\n    const char        *func;\n    int                line;\n    mln_array_t        subspans;\n    struct mln_span_s *parent;\n} mln_span_t;\n\nextern int mln_span_start(void);\nextern void mln_span_stop(void);\nextern void mln_span_dump(void);\nextern void mln_span_release(void);\n</code></pre>\n<p>\u8fd9\u91cc\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6570\u636e\u7ed3\u6784<code>mln_span_t</code>\uff0c\u7528\u6765\u5b58\u653e\u51fd\u6570\u8c03\u7528\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u65f6\u7684\u65f6\u95f4\u6233\uff0c\u4ee5\u53ca\u51fd\u6570\u6240\u5728\u6e90\u6587\u4ef6\u7684\u4fe1\u606f\u3002\u8fd8\u5305\u542b\u4e86\u8fd9\u4e2a\u51fd\u6570\u4e2d\u8c03\u7528\u7684\u5176\u4ed6\u51fd\u6570\u7684\u8c03\u7528\u65f6\u957f\u4fe1\u606f\uff0c\u4ee5\u53ca\u4e00\u4e2a\u6307\u5411\u4e0a\u4e00\u7ea7\u8c03\u7528\uff08\u4e5f\u5c31\u662f\u8c03\u7528\u5f53\u524d\u51fd\u6570\u7684\u51fd\u6570\uff09\u4fe1\u606f\u7684\u6307\u9488\u3002</p>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u6211\u4eec\u7684\u51fd\u6570\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u6211\u4eec\u904d\u5386\u8fd9\u4e2a\u7ed3\u6784\u5c31\u80fd\u62ff\u5230\u5b8c\u6574\u7684\u8c03\u7528\u5173\u7cfb\u53ca\u5176\u8c03\u7528\u7ec6\u8282\u3002</p>\n<h4>span.c</h4>\n<pre><code class=\"language-c\">#include &lt;stdlib.h&gt;\n#include &lt;string.h&gt;\n#include \"span.h\"\n#include \"mln_stack.h\"\n#include \"mln_func.h\"\n\nstatic mln_stack_t *callstack = NULL;\nstatic mln_span_t *root = NULL;\n\nstatic void mln_span_entry(const char *file, const char *func, int line);\nstatic void mln_span_exit(const char *file, const char *func, int line);\nstatic mln_span_t *mln_span_new(mln_span_t *parent, const char *file, const char *func, int line);\nstatic void mln_span_free(mln_span_t *s);\n\nstatic mln_span_t *mln_span_new(mln_span_t *parent, const char *file, const char *func, int line)\n{\n    mln_span_t *s;\n    struct mln_array_attr attr;\n\n    if (parent != NULL) {\n        s = (mln_span_t *)mln_array_push(&amp;parent-&gt;subspans);\n    } else {\n        s = (mln_span_t *)malloc(sizeof(mln_span_t));\n    }\n    if (s == NULL) return NULL;\n\n    memset(&amp;s-&gt;begin, 0, sizeof(struct timeval));\n    memset(&amp;s-&gt;end, 0, sizeof(struct timeval));\n    s-&gt;file = file;\n    s-&gt;func = func;\n    s-&gt;line = line;\n    attr.pool = NULL;\n    attr.pool_alloc = NULL;\n    attr.pool_free = NULL;\n    attr.free = (array_free)mln_span_free;\n    attr.size = sizeof(mln_span_t);\n    attr.nalloc = 7;\n    if (mln_array_init(&amp;s-&gt;subspans, &amp;attr) &lt; 0) {\n        if (parent == NULL) free(s);\n        return NULL;\n    }\n    s-&gt;parent = parent;\n    return s;\n}\n\nstatic void mln_span_free(mln_span_t *s)\n{\n    if (s == NULL) return;\n    mln_array_destroy(&amp;s-&gt;subspans);\n    if (s-&gt;parent == NULL) free(s);\n}\n\nint mln_span_start(void)\n{\n    struct mln_stack_attr sattr;\n\n    mln_func_entry_callback_set(mln_span_entry);\n    mln_func_exit_callback_set(mln_span_exit);\n\n    sattr.free_handler = NULL;\n    sattr.copy_handler = NULL;\n    if ((callstack = mln_stack_init(&amp;sattr)) == NULL)\n        return -1;\n\n    return 0;\n}\n\nvoid mln_span_stop(void)\n{\n    mln_func_entry_callback_set(NULL);\n    mln_func_exit_callback_set(NULL);\n    mln_stack_destroy(callstack);\n}\n\nvoid mln_span_release(void)\n{\n    mln_span_free(root);\n}\n\nstatic void mln_span_format_dump(mln_span_t *span, int blanks)\n{\n    int i;\n    mln_span_t *sub;\n\n    for (i = 0; i &lt; blanks; ++i)\n        printf(\" \");\n    printf(\"| %s at %s:%d takes %lu (us)\\n\", \\\n           span-&gt;func, span-&gt;file, span-&gt;line, \\\n           (span-&gt;end.tv_sec * 1000000 + span-&gt;end.tv_usec) - (span-&gt;begin.tv_sec * 1000000 + span-&gt;begin.tv_usec));\n\n    for (i = 0; i &lt; mln_array_nelts(&amp;(span-&gt;subspans)); ++i) {\n        sub = ((mln_span_t *)mln_array_elts(&amp;(span-&gt;subspans))) + i;\n        mln_span_format_dump(sub, blanks + 2);\n    }\n}\n\nvoid mln_span_dump(void)\n{\n    if (root != NULL)\n        mln_span_format_dump(root, 0);\n}\n\nstatic void mln_span_entry(const char *file, const char *func, int line)\n{\n    mln_span_t *span;\n\n    if ((span = mln_span_new(mln_stack_top(callstack), file, func, line)) == NULL) {\n        fprintf(stderr, \"new span failed\\n\");\n        exit(1);\n    }\n    if (mln_stack_push(callstack, span) &lt; 0) {\n        fprintf(stderr, \"push span failed\\n\");\n        exit(1);\n    }\n    if (root == NULL) root = span;\n    gettimeofday(&amp;span-&gt;begin, NULL);\n}\n\nstatic void mln_span_exit(const char *file, const char *func, int line)\n{\n    mln_span_t *span = mln_stack_pop(callstack);\n    if (span == NULL) {\n        fprintf(stderr, \"call stack crashed\\n\");\n        exit(1);\n    }\n    gettimeofday(&amp;span-&gt;end, NULL);\n}\n</code></pre>\n<p>\u8fd9\u91cc\u5c31\u662f\u8017\u65f6\u7edf\u8ba1\u6240\u9700\u8981\u7684\u6240\u6709\u51fd\u6570\u5b9a\u4e49\u3002\u5229\u7528\u4e00\u4e2a\u6808\u6570\u636e\u7ed3\u6784\u6765\u4fdd\u8bc1\u51fd\u6570\u7684\u8c03\u7528\u5173\u7cfb\uff0c\u7136\u540e\u5728\u51fd\u6570\u7684\u5165\u53e3\u56de\u8c03\u5904\u521b\u5efa<code>mln_span_t</code>\u7ed3\u70b9\u8bb0\u5f55\u8d77\u59cb\u65f6\u95f4\u548c\u51fd\u6570\u4fe1\u606f\u5e76\u5165\u6808\uff0c\u5728\u51fa\u53e3\u56de\u8c03\u5904\u8bb0\u5f55\u7ed3\u675f\u65f6\u95f4\u5e76\u51fa\u6808\u3002</p>\n<h4>a.c</h4>\n<pre><code class=\"language-c\">#include \"span.h\"\n#include \"mln_func.h\"\n\nMLN_FUNC(int, abc, (int a, int b), (a, b), {\n    return a + b;\n})\n\nMLN_FUNC(static int, bcd, (int a, int b), (a, b), {\n    return abc(a, b) + abc(a, b);\n})\n\nint main(void)\n{\n    mln_span_start();\n    bcd(1, 2);\n    mln_span_stop();\n    mln_span_dump();\n    mln_span_release();\n    return 0;\n}\n</code></pre>\n<p>\u8fd9\u91cc\u8fd8\u662f\u90a3\u4e2a\u914d\u65b9\uff0c\u5c31\u662f\u8c03\u7528<code>bcd</code>\uff0c\u7136\u540e<code>bcd</code>\u8c03\u7528<code>abc</code>\u3002\u6211\u4eec\u8fd9\u6b21\u5728<code>main</code>\u51fd\u6570\u4e2d\u4f7f\u7528<code>span.h</code>\u4e2d\u58f0\u660e\u7684\u51fd\u6570\u3002</p>\n<p>\u4e00\u8d77\u6765\u7b80\u5355\u7f16\u8bd1\u4e00\u4e0b\uff1a</p>\n<pre><code class=\"language-bash\">cc -o a span.c a.c -I /usr/local/melon/include -L /usr/local/melon/lib -lmelon -DMLN_FUNC_FLAG\n</code></pre>\n<p>\u7136\u540e\u8fd0\u884c\u4e00\u4e0b\uff1a</p>\n<pre><code>./a\n\n| bcd at a.c:8 takes 2 (us)\n  | abc at a.c:4 takes 0 (us)\n  | abc at a.c:4 takes 0 (us)\n</code></pre>\n<h2>\u5c0f\u7ed3</h2>\n<p><a href=\"https://github.com/Water-Melon/Melon\" rel=\"nofollow\">Melon</a>\u7684\u51fd\u6570\u6a21\u677f\u5176\u5b9e\u8bbe\u8ba1\u4e4b\u521d\u4e5f\u662f\u4e3a\u4e86\u53ef\u89c2\u6d4b\u6027\uff0c\u56e0\u4e3a GCC \u4ec5\u652f\u6301\u4e86 constructor \u548c destructor \u3002\u5982\u679c\u663e\u5f0f\u5730\u5728\u4ee3\u7801\u4e2d\u52a0\u5165\u5404\u79cd\u8ddf\u8e2a\u51fd\u6570\u8c03\u7528\uff0c\u5c31\u4f1a\u8ba9\u6574\u4e2a\u51fd\u6570\u5b9a\u4e49\u770b\u7740\u975e\u5e38\u4e0d\u8fde\u8d2f\u548c\u6742\u4e71\u3002\u56e0\u6b64\u9009\u62e9\u4e86\u5f53\u524d\u7684\u8fd9\u4e2a\u4f7f\u7528\u65b9\u5f0f\uff0c\u4f46\u4e5f\u4e0d\u53ef\u907f\u514d\u7684\u5f15\u5165\u4e86\u770b\u4f3c\u6ca1\u4ec0\u4e48\u7528\u9014\u7684\u5b9e\u53c2\u90e8\u5206\u3002</p>\n<p>\u53e6\u5916\uff0cMelon \u5e93\u652f\u6301\u6a21\u5757\u9009\u62e9\u6027\u7f16\u8bd1\uff0c\u56e0\u6b64\u51fd\u6570\u6a21\u7248\u6a21\u5757\u53ef\u4ee5\u5355\u72ec\u7f16\u8bd1\u6210\u5e93\uff0c\u6362\u8a00\u4e4b\uff0c\u8fd9\u4e2a\u6a21\u5757\u662f\u5b8c\u5168\u65e0\u64cd\u4f5c\u7cfb\u7edf\u4f9d\u8d56\u7684\uff0c\u5355\u7247\u673a\u7684\u5c0f\u4f19\u4f34\u4eec\u53ef\u4ee5\u968f\u610f\u53d6\u7528\u3002</p>\n<p>\u611f\u8c22\u9605\u8bfb\uff01</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/lcj2class", 
        "name": "lcj2class", 
        "avatar": "https://cdn.v2ex.com/avatar/b23f/7246/58407_large.png?m=1766834202"
      }, 
      "url": "https://www.v2ex.com/t/997278", 
      "title": "\u5728 C \u4e2d\uff0c\u5982\u4f55\u6b63\u786e\u62f7\u8d1d\u5b57\u7b26\u4e32", 
      "id": "https://www.v2ex.com/t/997278", 
      "date_published": "2023-12-03T10:54:50+00:00", 
      "content_html": "- <a target=\"_blank\" href=\"https://liujiacai.net/blog/2023/12/02/strcpy/\" rel=\"nofollow noopener\">https://liujiacai.net/blog/2023/12/02/strcpy/</a><br /><br />\u8fd9\u4e24\u5929\u7a0d\u5fae\u603b\u7ed3\u4e86\u4e0b strcpy \u7684\u95ee\u9898\uff0c\u6b22\u8fce\u5927\u5bb6\u6279\u8bc4\u6307\u6b63\u3002"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/kkkbbb", 
        "name": "kkkbbb", 
        "avatar": "https://cdn.v2ex.com/avatar/3d50/3deb/600947_large.png?m=1760170604"
      }, 
      "url": "https://www.v2ex.com/t/994162", 
      "date_modified": "2023-11-22T10:43:56+00:00", 
      "content_html": "<p>\u770b\u5230\u4e00\u4e2a\u4ee3\u7801\u81ea\u5b9a\u4e49\u6bb5\u5b9e\u73b0\u5982\u4e0b\uff1a</p>\n<pre><code>typedef void (*myown_call)(void);\n\n#define func_init(func)                                                        \\\n  __attribute__((section(\"myown\"), aligned(__alignof__(myown_call))))          \\\n  myown_call _fn_##func = func\n  \nextern myown_call __start_myown;\nextern myown_call __stop_myown;\n\nvoid do_initcalls(void) {\n  myown_call *pfun = &amp;__start_myown;\n  do {\n    (*pfun)();\n    ++pfun;\n  } while (pfun &lt; &amp;__stop_myown);\n}\n</code></pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u662f\u5b9e\u73b0\u521d\u59cb\u5316\u903b\u8f91\u7684\uff0c\u6211\u5728\u7f51\u4e0a\u770b\u5230\u8981\u60f3\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u6bb5\u6570\u636e\u52a0\u8f7d\uff0c\u9700\u8981\u5728\u94fe\u63a5\u811a\u672c\u4e2d\u6307\u5b9a__start_myown \u548c__stop_myown \u7684\u5730\u5740\u4f4d\u7f6e\uff0c\u4f46\u662f\u5728\u4ee3\u7801\u7684\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u6ca1\u6709\u770b\u5230\u76f8\u5173\u7684\u8bbe\u7f6e\uff0c\u4e0d\u592a\u6e05\u695a__start_myown \u3001__stop_myown \u7684\u5730\u5740\u7f16\u8bd1\u5668\u662f\u5982\u4f55\u5206\u914d\u7684\uff0c\u53c8\u61c2\u5f97\u5927\u4f6c\u53ef\u4ee5\u7ed9\u89e3\u91ca\u4e0b\u4e48\uff1f</p>\n", 
      "date_published": "2023-11-22T06:05:08+00:00", 
      "title": "c \u8bed\u8a00\u4e2d\u81ea\u5b9a\u4e49 section \u6bb5\u95ee\u9898\u8bf7\u6559", 
      "id": "https://www.v2ex.com/t/994162"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/Exxfire", 
        "name": "Exxfire", 
        "avatar": "https://cdn.v2ex.com/gravatar/d0c05e7c27c838082240f375e003f5ec?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/990768", 
      "date_modified": "2023-11-11T08:52:21+00:00", 
      "content_html": "<p>\u6211\u662f\u4e00\u540d\u4e3b\u8981\u4f7f\u7528 C \u8bed\u8a00\u5f00\u53d1\u7684\u7a0b\u5e8f\u5458\u3002\n\u5de5\u4f5c\u4e2d\u7ecf\u5e38\u9700\u8981\u9605\u8bfb\u4ee3\u7801\uff0cC \u8bed\u8a00\u7684\u4e0d\u5c11\u5de5\u7a0b\u7684\u4ee3\u7801\u5f53\u4e2d\u7528\u5230\u4e86\u5f88\u591a\u7684\u9884\u5904\u7406\u6307\u4ee4+\u5b8f\u6765\u63a7\u5236\u6253\u5f00\u3001\u5173\u95ed\u8f6f\u4ef6\u7684\u4e00\u4e9b\u529f\u80fd\uff0c\u8fd9\u6837\u4f7f\u7528\u8d77\u6765\u5f88\u65b9\u4fbf\uff0c\u4f46\u662f\u6bd4\u8f83\u5f71\u54cd\u9605\u8bfb\u4f53\u9a8c\uff0c\u6709\u6ca1\u6709\u4ec0\u4e48 vs code \u7684\u63d2\u4ef6\u6216\u8005\u5de5\u5177\uff0c\u53ef\u4ee5\u628a\u6ca1\u6253\u5f00\u90e8\u5206\u7684\u4ee3\u7801\u7ed9\u8fc7\u6ee4\u6389\uff0c\u7c7b\u4f3c\u9884\u7f16\u8bd1\u4e4b\u540e\u7684\u4ee3\u7801\uff0c\u4f46\u662f\u4e0d\u4f1a\u50cf\u9884\u7f16\u8bd1\u4e00\u6837\u628a\u5934\u6587\u4ef6\u548c\u5b8f\u5c55\u5f00\u3002</p>\n", 
      "date_published": "2023-11-10T10:15:20+00:00", 
      "title": "C \u8bed\u8a00\u7684\u6e90\u7801\u8fc7\u6ee4\u529f\u80fd\u7684\u5de5\u5177", 
      "id": "https://www.v2ex.com/t/990768"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/kanhongj", 
        "name": "kanhongj", 
        "avatar": "https://cdn.v2ex.com/gravatar/bb4edd3290051c46a31a7e2c7ebdf17c?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/989854", 
      "title": "\u6c42\u52a9 libcurl \u7684 curl_easy_pause() \u4f7f\u7528\u65b9\u6cd5", 
      "id": "https://www.v2ex.com/t/989854", 
      "date_published": "2023-11-08T05:58:36+00:00", 
      "content_html": "<p><a href=\"https://curl.se/libcurl/c/curl_easy_pause.html\" rel=\"nofollow\">\u5b98\u65b9 API \u8bf4\u660e</a></p>\n<p>\u610f\u601d\u662f\u6700\u597d\u5728</p>\n<p><strong>CURLOPT_WRITEFUNCTION</strong>\n<strong>CURLOPT_READFUNCTION</strong>\n<strong>CURLOPT_PROGRESSFUNCTION</strong></p>\n<p>\u4f7f\u7528\u4e48\uff1f\u6709\u6ca1\u6709\u5927\u4f6c\u7528\u8fc7,\u6216\u8005\u6709\u76f8\u5173\u4f8b\u5b50\u7684(\u641c\u7d22\u4e86\u5f88\u591a\uff0c\u6ca1\u627e\u5230)</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/WilliamColton", 
        "name": "WilliamColton", 
        "avatar": "https://cdn.v2ex.com/avatar/3a5e/dae7/552863_large.png?m=1750001532"
      }, 
      "url": "https://www.v2ex.com/t/989412", 
      "date_modified": "2023-11-07T02:57:26+00:00", 
      "content_html": "\u5982\u9898\uff0c\u6700\u8fd1\u53d1\u73b0\u5bf9 C \u8bed\u8a00\u7684\u4e86\u89e3\u8fd8\u4e0d\u591f\u6df1\u5165\uff0c\u5982\u51fd\u6570\u4f20\u53c2\u987a\u5e8f\uff0c\u5c40\u90e8\u53d8\u91cf\u548c\u5168\u5c40\u53d8\u91cf\u7684\u8d4b\u503c\u7b49\uff0c\u5404\u4f4d\u6709\u4ec0\u4e48\u597d\u7684\u4e66\u7c4d\u63a8\u8350\u4e48\uff08\u53ef\u4ee5\u548c\u6c47\u7f16\u7ed3\u5408\u8d77\u6765\u8bb2\uff09\uff0c\u6700\u8fd1\u5bf9\u8fd9\u4e2a\u633a\u611f\u5174\u8da3\uff0c\u540c\u65f6\u4e5f\u5728\u5b66\u4e60\u6c47\u7f16\uff0c\u6240\u4ee5\u529d\u6211\u653e\u5f03\u4e4b\u7c7b\u7684\u8bdd\u5c31\u4e0d\u7528\u8bf4\u4e86\uff0c\u6bd5\u7adf\u662f\u5174\u8da3", 
      "date_published": "2023-11-07T02:54:03+00:00", 
      "title": "\u5404\u4f4d\u6709\u4ec0\u4e48\u6df1\u5165\u4e86\u89e3 C \u8bed\u8a00\u7684\u4e66\u561b\uff1f", 
      "id": "https://www.v2ex.com/t/989412"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/cppc", 
        "name": "cppc", 
        "avatar": "https://cdn.v2ex.com/avatar/574d/b9ce/458849_large.png?m=1772701431"
      }, 
      "url": "https://www.v2ex.com/t/985468", 
      "title": "\u4e0d\u719f\u6089 cmake,\u8bf7\u6559\u4e00\u4e0b\u591a\u6a21\u5757\u9879\u76ee\u7684 cmake \u5199\u6cd5", 
      "id": "https://www.v2ex.com/t/985468", 
      "date_published": "2023-10-25T16:13:37+00:00", 
      "content_html": "<p>\u9879\u76ee\u7ed3\u6784\u662f\u4e24\u4e2a\u5b50\u6a21\u5757,\u76ee\u5f55\u5982\u4e0b</p>\n<pre><code>PROJECT-ROOT\n\u2502  CMakeLists.txt\n\u2502\n\u251c\u2500app\n\u2502  \u2502  CMakeLists.txt\n\u2502  \u2502\n\u2502  \u251c\u2500include\n\u2502  \u2502      misc.h\n\u2502  \u2502\n\u2502  \u2514\u2500src\n\u2502          main.cpp\n\u2502\n\u2514\u2500lib-example\n    \u2502  CMakeLists.txt\n    \u2502\n    \u251c\u2500include\n    \u2502      lib.h\n    \u2502\n    \u2514\u2500src\n            lib.cpp\n</code></pre>\n<p>app \u662f\u53ef\u6267\u884c\u6587\u4ef6\uff0clib-example \u662f\u52a8\u6001\u5e93\u3002app \u8fd9\u4e2a\u9879\u76ee\u9700\u8981\u52a8\u6001\u94fe\u63a5\u5230 lib-example,\u5e76\u4e14\u4f7f\u7528 lib-example \u7684\u5934\u6587\u4ef6\u3002\u7f51\u4e0a\u6709\u8d44\u6599\u4ecb\u7ecd\u7c7b\u4f3c\u7684\u7528\u6cd5\uff0c\u6211\u62ff\u8fc7\u6765\u6539\u4e86\u4e00\u4e0b,\u6ca1\u641e\u6210\u529f\u3002</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/BeiChuanAlex", 
        "name": "BeiChuanAlex", 
        "avatar": "https://cdn.v2ex.com/avatar/b0a2/f448/609975_large.png?m=1746262792"
      }, 
      "url": "https://www.v2ex.com/t/984327", 
      "date_modified": "2023-10-22T23:18:03+00:00", 
      "content_html": "<p>\u6700\u8fd1\u5728\u5b66 c \uff0c\u5e0c\u671b\u627e\u4e2a c \u7684\u5f00\u6e90\u9879\u76ee\u770b\u770b\uff0c\u6700\u597d\u662f\u7f51\u7edc tcp/ip \u76f8\u5173\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u5176\u4ed6\u7684\u4e5f\u53ef\u4ee5\uff0c\u661f\u661f\u591a\u70b9\u7684\uff0c\u5e0c\u671b\u5404\u4f4d\u5927\u4f6c\u63a8\u8350\u4e00\u4e0b\u3002</p>\n<p>ps\uff1a\n1.\u5982\u679c\u6709\u70b9\u6c47\u7f16\u4e5f\u884c\uff0c\u6211\u4e5f\u60f3\u518d\u5b66\u5b66\u6c47\u7f16\n2.\u7269\u8054\u7f51\u76f8\u5173\u7684\u4e5f\u884c\uff0c\u5355\u7247\u673a\u65b9\u5411\n3.nginx \u5c31\u7b97\u4e86\uff0c\u4e00\u53e3\u5403\u4e0d\u4e86\u4e2a\u80d6\u5b50\uff0c\u5e0c\u671b\u80fd\u6709\u4e2a\u603b\u4f53\u7684\u4ee3\u7801\u91cf\u5c11\u70b9\u7684\u3002</p>\n", 
      "date_published": "2023-10-22T15:51:04+00:00", 
      "title": "\u5927\u5bb6\u6709\u6ca1\u6709\u503c\u5f97\u63a8\u8350\u7684 c \u8bed\u8a00\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u7528\u6765\u5b66\u4e60\u6216\u8005\u8d21\u732e\u7684\u3002", 
      "id": "https://www.v2ex.com/t/984327"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/gooooood", 
        "name": "gooooood", 
        "avatar": "https://cdn.v2ex.com/avatar/5a95/eb6c/653517_large.png?m=1699586333"
      }, 
      "url": "https://www.v2ex.com/t/983240", 
      "date_modified": "2023-10-18T11:31:30+00:00", 
      "content_html": "<pre><code>typedef struct {\n    int width;\n    int height;\n    int depth;\n} INFO_T;\n\nint Send(int infoNum, const INFO_T *pInfo[])\n{\n\tINFO_T tInfo;\n\tfor (int m = 0; m &lt; infoNum; m++) {\n\t\tmemcpy(&amp;tInfo, &amp;pInfo[m], sizeof(INFO_T));\n\t\tprintf(\"info=%d \\n\", tInfo.width);  //\u8fd9\u6761\u8bed\u53e5\u662f\u6b63\u5e38\u7684\n\t\tprintf(\"info=%d \\n\", pInfo[m]-&gt;width); //\u6309\u7406\u8bf4\u8fd9\u6761\u548c\u4e0a\u9762\u4e00\u6761\u662f\u7b49\u4ef7\u7684\uff0c\u4f46\u662f\u52a0\u5165\u8fd9\u6761\u8bed\u53e5\u540e\u5c31\u4f1a core \u5d29\u6e83\n\t}\n}\n</code></pre>\n", 
      "date_published": "2023-10-18T10:44:45+00:00", 
      "title": "\u6c42\u5e2e\u5fd9\u770b\u4e00\u4e0b\u8fd9\u4e2a C \u4ee3\u7801\u4e3a\u4ec0\u4e48\u4f1a\u6bb5\u9519\u8bef\uff01", 
      "id": "https://www.v2ex.com/t/983240"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/monkeyNik", 
        "name": "monkeyNik", 
        "avatar": "https://cdn.v2ex.com/avatar/d196/0d1a/499929_large.png?m=1697247708"
      }, 
      "url": "https://www.v2ex.com/t/979065", 
      "title": "int \u578b\u8fd4\u56de\u503c\u6240\u80fd\u8868\u8fbe\u7684\u5185\u5bb9\u6781\u9650", 
      "id": "https://www.v2ex.com/t/979065", 
      "date_published": "2023-10-05T10:20:18+00:00", 
      "content_html": "<p>\u4ee5\u524d\u5f00\u53d1\u7684\u65f6\u5019\u7ecf\u5e38\u9047\u5230\u5bf9\u5916\u66b4\u9732\u7684\u51fd\u6570\u9700\u8981\u63d0\u4f9b\u4e00\u4e9b\u8fd4\u56de\u503c\uff0c\u6765\u8868\u8fbe\u51fd\u6570\u662f\u5426\u51fa\u9519\u3002</p>\n<p>\u4f46\u6709\u65f6\u5019\u4e00\u4e2a\u51fd\u6570\u53ef\u80fd\u51fa\u73b0\u591a\u79cd\u9519\u8bef\uff0c\u6240\u4ee5\u5355\u7eaf\u8fd4\u56de-1 \u4e5f\u65e0\u6cd5\u6ee1\u8db3\u9700\u8981\u3002\u6709\u4e9b\u4eba\u7684\u5904\u7406\u65b9\u5f0f\u662f\u589e\u52a0\u4e00\u4e2a errno \u6765\u6807\u8bb0\u9519\u8bef\u3002</p>\n<p>\u4f46\u4e2a\u4eba\u611f\u89c9\u8fd8\u662f\u6709\u4e9b\u9ebb\u70e6\uff0c\u800c\u4e14\u9700\u8981\u8003\u8651\u591a\u7ebf\u7a0b\u95ee\u9898\u3002</p>\n<p>\u6240\u4ee5\u5b9e\u73b0\u4e86\u8fd9\u6837\u4e00\u4e2a\u8fd4\u56de\u503c\u7ba1\u7406\u7684\u7ec4\u4ef6\u653e\u5230\u4e86 Melon \u5e93\u4e2d\u3002</p>\n<p>\u5148\u7ed9\u51fa\u4e00\u4e2a\u4f8b\u5b50\uff0c\u5927\u5bb6\u770b\u770b\u6548\u679c\u5427\u3002</p>\n<pre><code class=\"language-c\">#include \"mln_error.h\"\n\n#define OK    0\n#define NMEM  1\n\nint main(void)\n{\n    char msg[1024];\n    mln_string_t files[] = {\n        mln_string(\"a.c\"),\n    };\n    mln_string_t errs[] = {\n        mln_string(\"Success\"),\n        mln_string(\"No memory\"),\n    };\n    mln_error_init(files, errs, sizeof(files)/sizeof(mln_string_t), sizeof(errs)/sizeof(mln_string_t));\n    printf(\"%x %d [%s]\\n\", RET(OK), CODE(RET(OK)), mln_error_string(RET(OK), msg, sizeof(msg)));\n    printf(\"%x %d [%s]\\n\", RET(NMEM), CODE(RET(NMEM)), mln_error_string(RET(NMEM), msg, sizeof(msg)));\n    printf(\"%x %d [%s]\\n\", RET(2), CODE(RET(2)), mln_error_string(RET(2), msg, sizeof(msg)));\n    printf(\"%x %d [%s]\\n\", RET(0xff), CODE(RET(0xff)), mln_error_string(RET(0xff), msg, sizeof(msg)));\n    return 0;\n}\n</code></pre>\n<p>\u8fd9\u4e2a\u7a0b\u5e8f\u7684\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a</p>\n<pre><code>0 0 [Success]\nffffedff 1 [a.c:18:No memory]\nffffec01 255 [a.c:19:Unknown Code]\nffffeb01 255 [a.c:20:Unknown Code]\n</code></pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u901a\u8fc7\u4e00\u4e2a int \u503c\uff0c\u6211\u53ef\u4ee5\u83b7\u53d6\u5230\u9519\u8bef\u7801\u3001\u6587\u4ef6\u3001\u884c\u53f7\u751a\u81f3\u662f\u9519\u8bef\u7801\u5bf9\u5e94\u7684\u63cf\u8ff0\u3002</p>\n<p>\u5f53\u7136\u8fd9\u4e9b\u5185\u5bb9\u9700\u8981\u5728\u8fd4\u56de\u503c\u7ba1\u7406\u7ec4\u4ef6\u521d\u59cb\u5316\u7684\u65f6\u5019\u7ed9\u51fa\u3002</p>\n<p>\u8fd9\u6837\uff0c\u6bcf\u4e00\u4efd\u4ee3\u7801\u7684\u6bcf\u4e00\u4e2a\u4f7f\u7528<code>RET</code>\u751f\u6210\u7684\u9519\u8bef\u7801\u5c06\u662f\u5168\u9879\u76ee\u4e2d\u72ec\u4e00\u65e0\u4e8c\u7684\u4e00\u4e2a\u8d1f\u6574\u6570\u3002\u53ea\u8981\u6709\u4e86\u8fd9\u4e2a\u8d1f\u6574\u6570\uff0c\u540c\u65f6\u77e5\u9053\u4e86\u4ee3\u7801\u7684\u7248\u672c\uff0c\u5c31\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u5230\u9519\u8bef\u7684\u4f4d\u7f6e\u548c\u9519\u8bef\u5185\u5bb9\u3002</p>\n<p>\u611f\u5174\u8da3\u7684\u53ef\u4ee5\u770b\u4e00\u4e0b<a href=\"http://doc.melonc.io/en/error.html\" rel=\"nofollow\">Melon \u7684\u5b98\u65b9\u6587\u6863</a>\u4e86\u89e3\u8be6\u60c5\u3002</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/zxCoder", 
        "name": "zxCoder", 
        "avatar": "https://cdn.v2ex.com/gravatar/a442bec87d1dc5a6c29869ad5add87ee?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/978506", 
      "title": "\u521a\u521a\u7a81\u7136\u611f\u53d7\u5230\u4e86 C \u8bed\u8a00\u6307\u9488\u7684\u795e\u5947\u4e4b\u5904", 
      "id": "https://www.v2ex.com/t/978506", 
      "date_published": "2023-10-01T14:42:55+00:00", 
      "content_html": "<p>\u4ee5\u524d\u5927\u5b66\u5b66 C \u7684\u65f6\u5019\uff0c\u53ea\u662f\u8bf4\u6307\u9488\u5c31\u662f\u5730\u5740\u3002</p>\n<p>\u8fd9\u4e48\u591a\u5e74\u6ca1\u518d\u78b0 C \u8bed\u8a00\uff0c\u521a\u521a\u53d1\u73b0\uff0c\u5176\u5b9e\u6307\u9488\u9664\u4e86\u662f\u4e00\u4e2a\u5730\u5740\uff0c\u5e94\u8be5\u8fd8\u5305\u542b\u201c\u5982\u4f55\u53bb\u8bfb\u53d6\u8fd9\u4e2a\u5730\u5740\u7684\u503c\u201d\u8fd9\u4e2a\u4e1c\u897f\uff1f</p>\n<p>\u540c\u6837\u7684\u5730\u5740\uff0c\u8d4b\u503c\u7ed9 int \u6307\u9488\u548c char \u6307\u9488\uff0c\u8bfb\u53d6\u6765\u7684\u4e1c\u897f\u80af\u5b9a\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u611f\u89c9\u5f88\u6709\u610f\u601d\u3002</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/monkeyNik", 
        "name": "monkeyNik", 
        "avatar": "https://cdn.v2ex.com/avatar/d196/0d1a/499929_large.png?m=1697247708"
      }, 
      "url": "https://www.v2ex.com/t/977358", 
      "title": "\u5f00\u6e90 C \u8bed\u8a00\u5e93 Melon \u4e4b\u6a21\u5757\u9009\u62e9\u6027\u7f16\u8bd1", 
      "id": "https://www.v2ex.com/t/977358", 
      "date_published": "2023-09-26T10:58:53+00:00", 
      "content_html": "<p><a href=\"https://github.com/Water-Melon/Melon\" rel=\"nofollow\">Melon</a>\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u5f00\u6e90 C \u8bed\u8a00\u5e93\uff0c\u63d0\u4f9b\u4e86\u5404\u7c7b\u5f00\u53d1\u5e38\u7528\u7684\u7ec4\u4ef6\u3002\u65e0\u7b2c\u4e09\u65b9\u8f6f\u4ef6\u4f9d\u8d56\uff0c\u5f00\u7bb1\u5373\u7528\uff0c\u4e14\u914d\u5957\u4e2d\u82f1\u6587\u6587\u6863\u9f50\u5168\u3002</p>\n<h2>\u6982\u8ff0</h2>\n<p>\u6b63\u56e0\u4e3a Melon \u63d0\u4f9b\u4e86\u975e\u5e38\u591a\u7684\u7ec4\u4ef6\uff0c\u624d\u6709\u4e86\u4eca\u5929\u8fd9\u4e2a\u4e3b\u9898\u2014\u2014\u6a21\u5757\u9009\u62e9\u6027\u7f16\u8bd1\u3002\u6240\u8c13\u7684\u9009\u62e9\u6027\u7f16\u8bd1\uff0c\u7b80\u5355\u6765\u8bf4\u5c31\u662f\uff1a\u60f3\u8981\u7528\u4ec0\u4e48\u7ec4\u4ef6\u5c31\u7f16\u8bd1\u4ec0\u4e48\u7ec4\u4ef6\uff0c\u65e0\u5173\u7ec4\u4ef6\u4e0d\u4f1a\u7f16\u8bd1\u6210\u5e93\u3002</p>\n<p>\u8fd9\u6837\u505a\u6709\u4e24\u4e2a\u76ee\u7684\uff1a</p>\n<ol>\n<li>\u5254\u9664\u65e0\u5173\u5185\u5bb9\uff0c\u8ba9\u4f7f\u7528\u8005\u6709\u9009\u62e9\u81ea\u7531\u5ea6\uff0c\u53ea\u751f\u6210\u6709\u7528\u4e14\u7cbe\u7b80\u7684\u5e93\u6587\u4ef6</li>\n<li>\u517c\u987e\u65e0\u64cd\u4f5c\u7cfb\u7edf\u5f00\u53d1</li>\n</ol>\n<h2>\u4f7f\u7528</h2>\n<p>\u4e0b\u9762\u6211\u4eec\u5c31\u6f14\u793a\u4e00\u4e0b\u5982\u4f55\u8fdb\u884c\u6a21\u5757\u9009\u62e9\u6027\u7f16\u8bd1\u3002</p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u83b7\u53d6 Melon \u4ed3\u5e93</p>\n<pre><code class=\"language-shell\">git clone https://github.com/Water-Melon/Melon.git\n</code></pre>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u8fdb\u5165\u4ed3\u5e93</p>\n<pre><code class=\"language-shell\">cd Melon\n</code></pre>\n<p>\u7b2c\u4e09\u6b65\uff1a\u6267\u884c configure \uff0c\u6211\u4eec\u7684\u9009\u62e9\u6027\u7f16\u8bd1\u4e5f\u662f\u5728\u8fd9\u4e00\u6b65</p>\n<pre><code class=\"language-shell\">./configure --select=rbtree,array\n</code></pre>\n<p>\u8fd9\u91cc\u5047\u8bbe\u6211\u4eec\u4ec5\u7f16\u8bd1\u7ea2\u9ed1\u6811\u548c\u6570\u7ec4\u4e24\u4e2a\u7ec4\u4ef6\u3002</p>\n<p>\u7b2c\u56db\u6b65\uff1a\u6267\u884c make</p>\n<pre><code class=\"language-shell\">make\n</code></pre>\n<p>\u7b2c\u4e94\u6b65\uff1a\u6267\u884c make install</p>\n<pre><code class=\"language-shell\">make install\n</code></pre>\n<p>\u5982\u679c\u5b89\u88c5\u7684\u4f4d\u7f6e\u6743\u9650\u4e0d\u591f\uff0c\u5219\u9700\u8981</p>\n<pre><code class=\"language-shell\">sudo make install\n</code></pre>\n<p>\u7b2c\u4e09\u6b65\u4e2d<code>--select</code>\u7684\u53c2\u6570\u662f\u4ee5\u9017\u53f7\u5206\u9694\u7684\u6a21\u5757\u540d\u79f0\uff0c\u6ce8\u610f\u4e0d\u8981\u6709\u7a7a\u683c\u3002</p>\n<h2>\u6a21\u5757\u540d\u79f0</h2>\n<p>\u5728 Melon \u5b98\u65b9\u6587\u6863\u4e2d\uff0c\u6bcf\u4e2a\u7ec4\u4ef6\u7684\u6587\u6863\u5185\uff0c\u90fd\u7ed9\u51fa\u4e86\u5bf9\u5e94\u7684\u6a21\u5757\u540d\u79f0\u3002</p>\n<p>\u8fd8\u6709\u4e00\u79cd\u7b80\u5355\u7684\u529e\u6cd5\u53bb\u83b7\u53d6\u6a21\u5757\u540d\u3002\u5728 Melon \u4e2d\uff0c\u51e0\u4e4e\u6bcf\u4e2a\u6a21\u5757\u90fd\u6709\u4e00\u5bf9.c \u548c.h \u6587\u4ef6\u3002\u5f53\u6211\u4eec\u9700\u8981\u7528\u5230\u67d0\u4e2a\u6a21\u5757\uff0c\u4e00\u822c\u90fd\u662f include \u90a3\u4e2a\u6a21\u5757\u7684\u5934\u6587\u4ef6\u3002\u800c\u5934\u6587\u4ef6\u7684\u547d\u540d\u4e00\u822c\u662f<code>mln_&lt;module&gt;.h</code>\uff0c\u8fd9\u91cc\u7684<code>module</code>\u90e8\u5206\u5c31\u662f\u6a21\u5757\u540d\u79f0\uff08<code>&lt;&gt;</code>\u53ea\u662f\u7528\u6765\u7a81\u51fa\u6a21\u5757\u540d\u79f0\uff09\u3002</p>\n<h2>\u5b9e\u4f8b</h2>\n<p>\u4e0b\u9762\u5185\u5bb9\u4e3a\u7b14\u8005\u5728\u865a\u673a\u4e0a\u6267\u884c\u4e0a\u8ff0\u547d\u4ee4\u8fdb\u884c\u9009\u62e9\u6027\u7f16\u8bd1\u5b89\u88c5\u7684\u7ec8\u7aef\u8f93\u51fa\u5185\u5bb9\u3002</p>\n<pre><code class=\"language-shell\">$ git clone https://github.com/Water-Melon/Melon.git\nCloning into 'Melon'...\nremote: Enumerating objects: 6095, done.\nremote: Counting objects: 100% (1281/1281), done.\nremote: Compressing objects: 100% (480/480), done.\nremote: Total 6095 (delta 909), reused 1131 (delta 793), pack-reused 4814\nReceiving objects: 100% (6095/6095), 3.22 MiB | 1.02 MiB/s, done.\nResolving deltas: 100% (4417/4417), done.\n\n$ cd Melon\nnik@nik:~/test/Melon$ ./configure --select=rbtree,array\nInstallation Path \t[/usr/local/melon]\nMelang script Path \t[/usr/local/lib/melang]\nMelang dylib Path \t[/usr/local/lib/melang_dynamic]\nConfigure done!\n\nMelon$ make\ntest -d objs || mkdir objs\ntest -d lib || mkdir lib\ncc -Iinclude -c -Wall  -Werror -O3 -fPIC -o objs/mln_rbtree.o src/mln_rbtree.c\ncc -Iinclude -c -Wall  -Werror -O3 -fPIC -o objs/mln_array.o src/mln_array.c\ncc -o lib/libmelon.so objs/mln_rbtree.o objs/mln_array.o   -Wall -lpthread -Llib/ -ldl -shared -fPIC\nar -r lib/libmelon.a objs/mln_rbtree.o objs/mln_array.o \nar: creating lib/libmelon.a\n\nMelon$ sudo make install\ntest -d /usr/local/lib/melang || mkdir -p /usr/local/lib/melang\ntest -d /usr/local/melon || mkdir -p /usr/local/melon\ncp -fr lib /usr/local/melon\ncp -fr include /usr/local/melon\ntest -d /usr/local/melon/conf || cp -fr conf /usr/local/melon\ntest -d /usr/local/lib/melang/trace || cp -fr trace /usr/local/lib/melang\n</code></pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u53ea\u6709\u7ea2\u9ed1\u6811\u548c\u6570\u7ec4\u7684\u6e90\u6587\u4ef6\u88ab\u7f16\u8bd1\u548c\u6253\u5305\u6210\u5e93\u4e86\u3002</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/zzzkkk", 
        "name": "zzzkkk", 
        "avatar": "https://cdn.v2ex.com/gravatar/6e3e74eddd50888ba6210566f0669c97?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/974127", 
      "date_modified": "2023-10-07T10:31:44+00:00", 
      "content_html": "<pre><code class=\"language-c\">#include \"stdio.h\"\n#include \"stdlib.h\"\n#include \"string.h\"\nchar * reverseWords(char * s){\n        char * start, *  start2;\n        start = s;\n        while(*start != '\\0'){\n                start ++;\n        }\n        -- start;\n        char s2[strlen(s)];\n        char * s2p = s2;\n        while(start &gt; s){\n                while(*start == ' ') start --;\n                while(*start != ' ' &amp;&amp; start &gt;= s) start --;\n\n                start2 = start;\n                ++start2;\n\n                while(*start2 != ' '){\n                        *s2p++ = *start2++;\n                }\n                *s2p++ = ' ' ;\n        }\n        *s2p = '\\0';\n        start = s;\n        s2p = s2;\n        while(*s2p!='\\0') *start++ = *s2p++;\n        *start = '\\0';\n        return s;\n}\n\nint main(int argc, char ** argv){\n\n        char s[] = \"abc edf ghi lkm opq rst \";\n        printf(\"%s\\n\",reverseWords(s));\n\n}\n</code></pre>\n<p>\u5728 linux \u673a\u5668\u4e0a\u80fd\u7f16\u8bd1\u8fd0\u884c\u6b63\u786e  leetcode \u63d0\u793a==20==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000020 at pc 0x563392652f73 bp 0x7ffefb8e0c40 sp 0x7ffefb8e0c30\nREAD of size 1 at 0x602000000020 thread T0</p>\n<p>\u6211\u662f\u4e0d\u662f\u592a\u8d31\u4e86\uff1f</p>\n", 
      "date_published": "2023-09-15T07:23:46+00:00", 
      "title": "\u8fd9\u5e74\u5934\u641e c \u8fd8\u6709\u524d\u9014\u5417 \u770b\u770b\u6211\u7684 leetcode \u7b2c 151 \u9898\u76ee \u53cd\u8f6c\u5b57\u7b26\u4e32", 
      "id": "https://www.v2ex.com/t/974127"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/monkeyNik", 
        "name": "monkeyNik", 
        "avatar": "https://cdn.v2ex.com/avatar/d196/0d1a/499929_large.png?m=1697247708"
      }, 
      "url": "https://www.v2ex.com/t/973160", 
      "title": "\u767e\u53d8\u5f00\u6e90 C \u8bed\u8a00\u5e93\u65e5\u5fd7\u6a21\u5757", 
      "id": "https://www.v2ex.com/t/973160", 
      "date_published": "2023-09-12T14:46:21+00:00", 
      "content_html": "<p>\u672c\u6587\u5411\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e2a\u540d\u4e3a<a href=\"https://github.com/Water-Melon/Melon\" rel=\"nofollow\">Melon</a>\u7684\u5f00\u6e90 C \u8bed\u8a00\u5e93\u7684\u65e5\u5fd7\u6a21\u5757\u3002</p>\n<h3>\u7b80\u8ff0 Melon</h3>\n<p>Melon \u662f\u4e00\u4e2a\u5305\u542b\u4e86\u5f00\u53d1\u4e2d\u5e38\u7528\u7684\u5404\u7c7b\u7ec4\u4ef6\u7684\u5f00\u6e90 C \u8bed\u8a00\u5e93\uff0c\u652f\u6301 Linux \u3001MacOS \u3001Windows \u7cfb\u7edf\uff0c\u53ef\u7528\u4e8e\u670d\u52a1\u5668\u5f00\u53d1\u4ea6\u53ef\u7528\u4e8e\u5d4c\u5165\u5f0f\u5f00\u53d1\uff0c\u65e0\u7b2c\u4e09\u65b9\u8f6f\u4ef6\u4f9d\u8d56\uff0c\u5b89\u88c5\u7b80\u5355\uff0c\u5f00\u7bb1\u5373\u7528\uff0c\u4e2d\u82f1\u6587\u6587\u6863\u914d\u5957\u9f50\u5168\u3002</p>\n<h3>\u65e5\u5fd7\u6a21\u5757</h3>\n<p>\u65e5\u5fd7\u662f Melon \u5e93\u63d0\u4f9b\u7684\u901a\u7528\u7ec4\u5efa\u4e4b\u4e00\uff0c\u5728\u4ecb\u7ecd\u5176\u7279\u6027\u524d\uff0c\u6211\u4eec\u5148\u6765\u770b\u4e00\u4e0b\u5b83\u7684\u7b80\u5355\u4f7f\u7528\u793a\u4f8b\u3002</p>\n<pre><code class=\"language-c\">#include \"mln_log.h\"\n\nint main(int argc, char *argv[])\n{\n    mln_log(debug, \"This will be outputted to stderr\\n\");\n    mln_log_init(NULL);\n    mln_log(debug, \"This will be outputted to stderr and log file\\n\");\n    return 0;\n}\n</code></pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u4f7f\u7528\u4e0e\u6211\u4eec\u5e38\u7528\u7684<code>printf</code>\u6216<code>fprintf</code>\u5f88\u76f8\u4f3c\u3002</p>\n<p>\u540c\u65f6\uff0c\u4ece\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u4e5f\u53ef\u4ee5\u770b\u5230\u8fd9\u4e2a\u65e5\u5fd7\u6a21\u5757\u5141\u8bb8\u5728\u672a\u521d\u59cb\u5316\u60c5\u51b5\u4e0b\u4f7f\u7528\u3002\u5728\u672a\u521d\u59cb\u5316\u65f6\uff0c\u8fd9\u4e9b\u65e5\u5fd7\u90fd\u5c06\u88ab\u8f93\u51fa\u81f3<code>stderr</code>\u4e2d\u3002</p>\n<p>\u5f53\u7136\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>mln_log_init</code>\u5bf9\u65e5\u5fd7\u6a21\u5757\u8fdb\u884c\u521d\u59cb\u5316\u3002\u521d\u59cb\u5316\u540e\u5c06\u83b7\u5f97\u4e24\u79cd\u80fd\u529b\uff1a</p>\n<ol>\n<li>\u65e5\u5fd7\u4f1a\u8ddf\u636e\u4e0d\u540c\u7b49\u7ea7\u663e\u793a\u4e0d\u540c\u7684\u989c\u8272</li>\n<li>\u65e5\u5fd7\u5185\u5bb9\u65e2\u4f1a\u88ab\u8f93\u51fa\u5230 stderr \uff0c\u4e5f\u4f1a\u88ab\u8f93\u51fa\u5230 Melon \u914d\u7f6e\u4e2d\u6307\u5b9a\u7684\u65e5\u5fd7\u6587\u4ef6\u4e2d\uff08\u5173\u4e8e\u914d\u7f6e\uff0c\u8bf7\u53c2\u89c1<a href=\"http://doc.melonc.io/cn/conf.html\" rel=\"nofollow\">\u5b98\u65b9\u624b\u518c</a>\uff09\u3002</li>\n</ol>\n<h3>\u8fdb\u9636</h3>\n<p>\u663e\u7136\uff0c\u6211\u4eec\u7684\u65e5\u5fd7\u4e0d\u4ec5\u4ec5\u53ef\u4ee5\u505a\u8fd9\u4e9b\u4e8b\u60c5\u3002</p>\n<p>\u4e0b\u4e00\u6b65\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u5c06\u65e5\u5fd7\u5185\u5bb9\u505a\u81ea\u5b9a\u4e49\u5904\u7406\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u65e5\u5fd7\u56de\u8c03\u51fd\u6570\u3002</p>\n<p>\u8fd9\u91cc\u6d89\u53ca\u5230\u4e24\u4e2a\u65e5\u5fd7\u6a21\u5757\u7684\u51fd\u6570\uff1a</p>\n<ul>\n<li><code>mln_log_logger_get</code> \u83b7\u53d6\u5f53\u524d\u65e5\u5fd7\u5904\u7406\u51fd\u6570</li>\n<li><code>mln_log_logger_set</code> \u8bbe\u7f6e\u65e5\u5fd7\u5904\u7406\u51fd\u6570\u4e3a\u67d0\u4e2a\u6307\u5b9a\u7684\u51fd\u6570</li>\n</ul>\n<p>\u6211\u4eec\u770b\u4e00\u4e0b\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6211\u4eec\u5bf9\u4e0a\u9762\u7684\u4f8b\u5b50\u8fdb\u884c\u4e00\u987f\u6539\u9020\uff1a</p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n#include \"mln_log.h\"\n\nmln_logger_t old = NULL;\n\nstatic void mylogger(mln_log_t *log, mln_log_level_t level, const char *file,\n                     const char *func, int line, char *fmt, va_list args)\n{\n    printf(\"%s:%s:%d: %s\\n\", file, func, line, fmt);\n    if (old != NULL)\n        old(log, level, file, func, line, fmt, args);\n}\n\nint main(int argc, char *argv[])\n{\n    mln_log(debug, \"This will be outputted to stderr\\n\");\n    mln_log_init(NULL);\n  \n    old = mln_log_logger_get();\n    mln_log_logger_set(mylogger);\n  \n    mln_log(debug, \"This will be outputted to stderr and log file\\n\");\n    return 0;\n}\n</code></pre>\n<p>\u6211\u4eec\u589e\u52a0\u4e86\u4e00\u4e2a\u81ea\u5df1\u7684\u65e5\u5fd7\u5904\u7406\u51fd\u6570\u540d\u4e3a<code>mylogger</code>\uff0c\u5b83\u5c06\u622a\u83b7\u65e5\u5fd7\u7684\u5185\u5bb9\u53ca\u5176\u5173\u8054\u4fe1\u606f\uff0c\u4f7f\u7528<code>printf</code>\u5c06\u8fd9\u4e9b\u4fe1\u606f\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa\uff08<code>stdout</code>\uff09\u4e2d\u3002\u7136\u540e\u518d\u4f7f\u7528\u539f\u6709\u7684\u65e5\u5fd7\u5904\u7406\u51fd\u6570\u5c06\u65e5\u5fd7\u8f93\u51fa\u5230\u7ec8\u7aef\u7684<code>stderr</code>\u548c\u65e5\u5fd7\u6587\u4ef6\u4e2d\u3002</p>\n<p>\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u968f\u610f\u5730\u5bf9\u65e5\u5fd7\u5185\u5bb9\u8fdb\u884c\u5904\u7406\u4e86\u3002</p>\n<h3>\u7ed3\u8bed</h3>\n<p>Melon \u7684\u65e5\u5fd7\u6a21\u5757\u5141\u8bb8\u5f00\u53d1\u8005\u5bf9\u5176\u8fdb\u884c\u4efb\u610f\u6269\u5c55\u6765\u6ee1\u8db3\u81ea\u5df1\u7684\u9700\u6c42\u3002</p>\n<p>\u53e6\u5916\uff0c\u8981\u8865\u5145\u4e00\u70b9\uff0c\u8fd9\u4e2a<code>mln_log</code>\u662f\u5141\u8bb8<strong>\u591a\u7ebf\u7a0b</strong>\u4f7f\u7528\u7684\u3002\u5e76\u4e14\u5bf9\u4e8e<strong>x86 \u67b6\u6784</strong>\uff0c\u5728\u4e0d\u8c03\u7528<code>mln_log_init</code>\u5bf9\u65e5\u5fd7\u8fdb\u884c\u521d\u59cb\u5316\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e2a\u51fd\u6570\u5c31\u662f\u591a\u7ebf\u7a0b\u53ef\u7528\u7684\u3002</p>\n<p>\u611f\u8c22\u9605\u8bfb\uff01</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/monkeyNik", 
        "name": "monkeyNik", 
        "avatar": "https://cdn.v2ex.com/avatar/d196/0d1a/499929_large.png?m=1697247708"
      }, 
      "url": "https://www.v2ex.com/t/972885", 
      "title": "\u6700\u597d\u7528\u7684 C \u8bed\u8a00 JSON \u89e3\u6790\u5668", 
      "id": "https://www.v2ex.com/t/972885", 
      "date_published": "2023-09-11T16:46:43+00:00", 
      "content_html": "<p>\u672c\u6587\u4ecb\u7ecd\u5f00\u6e90 C \u8bed\u8a00\u5e93<a href=\"https://github.com/Water-Melon/Melon\" rel=\"nofollow\">Melon</a>\u7684 JSON \u89e3\u6790\u5668\u3002</p>\n<p>\u76f8\u4fe1\u5f88\u591a\u8bfb\u8005\u90fd\u542c\u8bf4\u8fc7\u751a\u81f3\u4f7f\u7528\u8fc7 cJSON \u5f00\u6e90\u5e93\u3002\u90a3\u4e48\u672c\u6587\u5c31\u62ff cJSON \u4e0e Melon \u7684 JSON \u7ec4\u4ef6\u8fdb\u884c\u5bf9\u6bd4\u3002</p>\n<p>\u4e0b\u9762\u6211\u4eec\u5c31\u6765\u4e00\u8d77\u770b\u4e00\u770b\u3002</p>\n<h2>\u7f16\u7801 Encode</h2>\n<p>\u5047\u8bbe\u6211\u4eec\u8981\u6784\u5efa\u5982\u4e0b JSON\uff1a</p>\n<pre><code class=\"language-json\">{\n    \"name\": \"Awesome 4K\",\n    \"resolutions\": [\n        {\n            \"width\": 1280,\n            \"height\": 720\n        },\n        {\n            \"width\": 1920,\n            \"height\": 1080\n        },\n        {\n            \"width\": 3840,\n            \"height\": 2160\n        }\n    ]\n}\n</code></pre>\n<p>\u90a3\u4e48\uff0c\u6211\u4eec\u5148\u770b\u4e00\u4e0b<strong>cJSON</strong>\u7684\u6784\u5efa\u4ee3\u7801\uff1a</p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n#include &lt;cjson/cJSON.h&gt;\n\n//NOTE: Returns a heap allocated string, you are required to free it after use.\nchar *create_monitor_with_helpers(void)\n{\n    const unsigned int resolution_numbers[3][2] = {\n        {1280, 720},\n        {1920, 1080},\n        {3840, 2160}\n    };\n    char *string = NULL;\n    cJSON *resolutions = NULL;\n    size_t index = 0;\n\n    cJSON *monitor = cJSON_CreateObject();\n\n    if (cJSON_AddStringToObject(monitor, \"name\", \"Awesome 4K\") == NULL)\n    {\n        goto end;\n    }\n\n    resolutions = cJSON_AddArrayToObject(monitor, \"resolutions\");\n    if (resolutions == NULL)\n    {\n        goto end;\n    }\n\n    for (index = 0; index &lt; (sizeof(resolution_numbers) / (2 * sizeof(int))); ++index)\n    {\n        cJSON *resolution = cJSON_CreateObject();\n\n        if (cJSON_AddNumberToObject(resolution, \"width\", resolution_numbers[index][0]) == NULL)\n        {\n            goto end;\n        }\n\n        if (cJSON_AddNumberToObject(resolution, \"height\", resolution_numbers[index][1]) == NULL)\n        {\n            goto end;\n        }\n\n        cJSON_AddItemToArray(resolutions, resolution);\n    }\n\n    string = cJSON_Print(monitor);\n    if (string == NULL)\n    {\n        fprintf(stderr, \"Failed to print monitor.\\n\");\n    }\n\nend:\n    cJSON_Delete(monitor);\n    return string;\n}\n\nint main(void)\n{\n    char *p;\n    p = create_monitor_with_helpers();\n    printf(\"%s\\n\", p);\n    return 0;\n}\n</code></pre>\n<p>\u4e0b\u9762\uff0c\u6211\u4eec\u4e00\u8d77\u770b\u4e0b\u4f7f\u7528<strong>Melon \u7684 JSON \u7ec4\u4ef6</strong>\u7684\u4ee3\u7801\uff1a</p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n#include \"mln_json.h\"\n#include \"mln_log.h\"\n\nstatic mln_string_t *generate(void)\n{\n    mln_json_t j;\n    mln_string_t *ret;\n\n    mln_json_init(&amp;j);\n\n    mln_json_generate(&amp;j, \"{s:s,s:[{s:d,s:d},{s:d,s:d},{s:d,s:d}]}\", \\\n        \"name\", \"Awesome 4K\", \"resolutions\", \"width\", 1280, \"height\", 720, \\\n        \"width\", 1920, \"height\", 1080, \"width\", 3840, \"height\", 2160);\n    ret = mln_json_encode(&amp;j);\n\n    mln_json_destroy(&amp;j);\n\n    return ret;\n}\n\nint main(void)\n{\n    mln_string_t *p;\n    p = generate();\n    mln_log(none, \"%S\\n\", p);\n    return 0;\n}\n</code></pre>\n<h2>\u89e3\u7801 Decode</h2>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u5982\u4e0b JSON\uff1a</p>\n<pre><code class=\"language-json\">{\n    \"name\": \"Awesome 4K\",\n    \"resolutions\": [\n        {\n            \"width\": 1280,\n            \"height\": 720\n        }\n    ]\n}\n</code></pre>\n<p>\u4e0b\u9762\u4e00\u8d77\u6765\u770b\u4e0b\u89e3\u7801\uff0c\u8fd8\u662f\u5148\u4e0a<strong>cJSON</strong>\u7684\u4ee3\u7801\uff1a</p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n#include &lt;cjson/cJSON.h&gt;\n\n/* return 1 if the monitor supports full hd, 0 otherwise */\nint supports_full_hd(const char * const monitor)\n{\n    const cJSON *resolution = NULL;\n    const cJSON *resolutions = NULL;\n    cJSON *monitor_json = cJSON_Parse(monitor);\n    if (monitor_json == NULL)\n        return -1;\n\n    resolutions = cJSON_GetObjectItemCaseSensitive(monitor_json, \"resolutions\");\n    cJSON_ArrayForEach(resolution, resolutions)\n    {\n        cJSON *width = cJSON_GetObjectItemCaseSensitive(resolution, \"width\");\n        return width-&gt;valuedouble;\n    }\n\n    cJSON_Delete(monitor_json);\n    return -1;\n}\n\nint main(void)\n{\n    char p[] = \"{\\\"name\\\":\\\"Awesome 4K\\\",\\\"resolutions\\\":[{\\\"width\\\":1280,\\\"height\\\":720}]}\";\n    int i = supports_full_hd(p);\n    printf(\"%d\\n\", i);\n    return 0;\n}\n</code></pre>\n<p>\u63a5\u4e0b\u6765\u662f<strong>Melon \u7684 JSON \u7ec4\u4ef6</strong>\u7684\u89e3\u7801\u4ee3\u7801\uff1a</p>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n#include \"mln_json.h\"\n#include \"mln_log.h\"\n\nstatic int handler(mln_json_t *j, void *data)\n{\n    return (int)M_JSON_GET_DATA_NUMBER(j);\n}\n\nstatic int parse(mln_string_t *p)\n{\n    mln_json_t j;\n    mln_string_t exp = mln_string(\"resolutions.0.width\");\n    mln_json_decode(p, &amp;j);\n    return mln_json_parse(&amp;j, &amp;exp, handler, NULL);\n}\n\nint main(void)\n{\n    mln_string_t p = mln_string(\"{\\\"name\\\":\\\"Awesome 4K\\\",\\\"resolutions\\\":[{\\\"width\\\":1280,\\\"height\\\":720}]}\");\n    int i = parse(&amp;p);\n    mln_log(none, \"%d\\n\", i);\n    return 0;\n}\n</code></pre>\n<h2>\u7ed3\u8bed</h2>\n<p>Melon \u7684 JSON \u7ec4\u4ef6\u4e3b\u8981\u63d0\u4f9b\u4e86\u5982\u4e0b\u56db\u4e2a\u51fd\u6570\u6765\u4fbf\u4e8e\u4f7f\u7528\u8005\u6784\u5efa\u548c\u89e3\u6790 JSON\uff1a</p>\n<ul>\n<li><code>mln_json_decode</code>\u89e3\u7801 JSON \u5b57\u7b26\u4e32\u4e3a JSON \u7ed3\u6784\u4f53\u7ed3\u70b9</li>\n<li><code>mln_json_parse</code>\u4ece\u89e3\u7801\u7684 JSON \u7ed3\u6784\u4f53\u4e2d\uff0c\u6839\u636e\u7ed9\u5b9a\u8868\u8fbe\u5f0f\uff0c\u83b7\u53d6\u5bf9\u5e94\u7684 JSON \u5b50\u7ed3\u70b9</li>\n<li><code>mln_json_generate</code>\u6839\u636e\u7ed9\u5b9a\u7684\u683c\u5f0f\u4fe1\u606f\u6784\u5efa JSON \u7ed3\u6784\u4f53</li>\n<li><code>mln_json_encode</code>\u6839\u636e\u751f\u6210\u7684 JSON \u7ed3\u6784\u4f53\u751f\u6210 JSON \u5b57\u7b26\u4e32</li>\n</ul>\n<p>Melon \u7684 JSON \u7ec4\u4ef6\u63d0\u4f9b\u4e86\u6613\u4e8e\u9605\u8bfb\u548c\u4f7f\u7528\u7684\u51fd\u6570\u63a5\u53e3\uff0c\u66f4\u6613\u4e8e\u5f00\u53d1\u8005\u5bf9\u9879\u76ee\u7684\u7ef4\u62a4\u3002</p>\n<p>\u6b22\u8fce\u5927\u5bb6\u6765\u8bd5\u7528\u5f00\u6e90 C \u8bed\u8a00\u5e93 Melon \u3002</p>\n<p>Github\uff1a <a href=\"https://github.com/Water-Melon/Melon\" rel=\"nofollow\">https://github.com/Water-Melon/Melon</a></p>\n"
    }
  ]
}