{"id":409,"date":"2023-02-25T10:54:12","date_gmt":"2023-02-25T02:54:12","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=409"},"modified":"2023-04-29T21:36:13","modified_gmt":"2023-04-29T13:36:13","slug":"android-ndk-basic-c-precompile-macro-definition-macro-replacement","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/android-ndk-basic-c-precompile-macro-definition-macro-replacement\/","title":{"rendered":"Android NDK\u57fa\u78409\uff1aC_\u9884\u7f16\u8bd1_\u5b8f\u5b9a\u4e49_\u5b8f\u66ff\u6362"},"content":{"rendered":"<h2>include\u6307\u4ee4<\/h2>\n<pre><code class=\"language-c\">#include &lt;stdlib.h&gt;\n#include &lt;stdio.h&gt;\n\n\/\/\u9884\u7f16\u8bd1\uff08\u9884\u5904\u7406\uff09\uff0c\u4e3a\u7f16\u8bd1\u505a\u51c6\u5907\u5de5\u4f5c\uff0c\u5b8c\u6210\u4ee3\u7801\u6587\u672c\u7684\u66ff\u6362\u5de5\u4f5c\n\/\/C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include\n\/\/C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\crt\\src\n\n\/\/\u5934\u6587\u4ef6\u544a\u8bc9\u7f16\u8bd1\u5668\u6709\u8fd9\u6837\u4e00\u4e2a\u51fd\u6570\uff0c\u8fde\u63a5\u5668\u8d1f\u8d23\u627e\u5230\u8fd9\u4e2a\u51fd\u6570\u7684\u5b9e\u73b0\n\nvoid main() {\n    \/\/#include &quot;my.txt&quot;\n    \/\/printf(&quot;%s\\n&quot;, &quot;I am a little boy!&quot;);\n}<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>my.txt<\/p>\n<pre><code class=\"language-c\">printf(&quot;%s\\n&quot;, &quot;I am a little boy!&quot;);<\/code><\/pre>\n<h2>define\u6307\u4ee4<\/h2>\n<h3>\u5b9a\u4e49\u6807\u793a<\/h3>\n<pre><code class=\"language-c\">\/\/#ifdef __cplusplus \u6807\u8bc6\u652f\u6301C++\u8bed\u6cd5<\/code><\/pre>\n<h3>\u9632\u6b62\u6587\u4ef6\u91cd\u590d\u5f15\u5165<\/h3>\n<p>A.h<\/p>\n<pre><code class=\"language-c\">\/\/\u8001\u7248\u672c\uff1a\u5982\u679c\u6ca1\u6709\u5b9a\u4e49AH\uff0c\u5b9a\u4e49AH\n\/\/#ifndef AH\n\/\/#define AH\n\/\/#include &quot;B.h&quot;\n\/\/\n\/\/void printfA();\n\/\/\n\/\/#endif\n\n\/\/\u65b0\u7248\u672c\uff1a\u8be5\u5934\u6587\u4ef6\u53ea\u88ab\u5305\u542b\u4e00\u6b21\uff0c\u8ba9\u7f16\u8bd1\u5668\u81ea\u5b9a\u5904\u7406\u597d\u5faa\u73af\u5305\u542b\u95ee\u9898\n#pragma once\n#include &quot;B.h&quot;\n\nvoid printfA();<\/code><\/pre>\n<p>B.h<\/p>\n<pre><code class=\"language-c\">\/\/#ifndef BH\n\/\/#define BH\n\/\/#include &quot;A.h&quot;\n\/\/\n\/\/void printfB();\n\/\/\n\/\/#endif\n\n#pragma once\n#include &quot;A.h&quot;\n\nvoid printfB();<\/code><\/pre>\n<p>main.c<\/p>\n<pre><code class=\"language-c\">#include &lt;stdlib.h&gt;\n#include &lt;stdio.h&gt;\n\n#include &quot;A.h&quot;\n\nvoid printfA() {\n    printf(&quot;print A&quot;);\n}\n\nvoid main() {\n    printfA();\n}<\/code><\/pre>\n<h3>\u5b9a\u4e49\u5e38\u6570\uff08\u4fbf\u4e8e\u4fee\u6539\u4e0e\u9605\u8bfb\uff09<\/h3>\n<pre><code class=\"language-c\">#define MAX 100\n\/\/int MIN = 40;\n\nvoid main() {\n    int i = 90;\n    if (i &lt; MAX) {\n        printf(&quot;\u6bd4MAX\u5c0f..&quot;);\n    }\n}<\/code><\/pre>\n<h3>\u5b9a\u4e49\u201c\u5b8f\u51fd\u6570\u201d<\/h3>\n<pre><code class=\"language-c\">void jni_read() {\n    printf(&quot;read\\n&quot;);\n}\n\nvoid jni_write() {\n    printf(&quot;write\\n&quot;);\n}\n\n\/\/NAME\u662f\u53c2\u6570\n#define jni(NAME) jni_##NAME();\n\/\/webrtc JNI\u51fd\u6570\u540d\u79f0\u5f88\u957f\uff0c\u4e5f\u662fJOW\u5b8f\u51fd\u6570\u7f29\u77ed\u51fd\u6570\u540d\u79f0\n\n\/\/\u65e5\u5fd7\u8f93\u51fa\n\/\/__VA_ARGS__\u53ef\u53d8\u53c2\u6570\n\/\/#define LOG(FORMAT,...) printf(##FORMAT, __VA_ARGS__);\n\/\/\u65e5\u5fd7\u4f1a\u6709\u7ea7\u522b\n\/\/#define LOG_I(FORMAT,...) printf(&quot;INFO:&quot;); printf(##FORMAT, __VA_ARGS__);\n\/\/#define LOG_E(FORMAT,...) printf(&quot;ERRO:&quot;); printf(##FORMAT, __VA_ARGS__);\n\n\/\/\u5347\u7ea7\u7248\u672c\n#define LOG(LEVEL,FORMAT,...) printf(##LEVEL); printf(##FORMAT, __VA_ARGS__);\n#define LOG_I(FORMAT,...) LOG(&quot;INFO:&quot;, ##FORMAT, __VA_ARGS__);\n#define LOG_E(FORMAT,...) LOG(&quot;ERROR:&quot;, ##FORMAT, __VA_ARGS__);\n#define LOG_W(FORMAT,...) LOG(&quot;WARN:&quot;, ##FORMAT, __VA_ARGS__);\n\n\/\/Android\n\/\/#define LOGI(FORMAT,...) __android_log_print(ANDROID_LOG_INFO, &quot;jason&quot;, FORMAT, ##__VA_ARGS__);\n\/\/LOGI(&quot;%s&quot;,&quot;fix&quot;);\n\/\/\u66ff\u6362\n\/\/__android_log_print(ANDROID_LOG_INFO, &quot;yezhou&quot;, &quot;%s&quot;, &quot;fix&quot;);<\/code><\/pre>\n<pre><code class=\"language-c\">void main() {\n    jni(write); \/\/\u66ff\u6362\uff1ajni_write();\n\n    LOG_I(&quot;%s%d&quot;, &quot;\u5927\u5c0f\uff1a&quot;, 89);\n    \/\/\u66ff\u6362\u6210\uff1aprintf(&quot;INFO:&quot;); printf(&quot;%s%d&quot;, &quot;\u5927\u5c0f\uff1a&quot;, 89);\n\n    getchar();\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>include\u6307\u4ee4 #include &lt;stdlib.h&gt; #include &lt;stdio. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-409","post","type-post","status-publish","format-standard","hentry","category-android-ndk"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=409"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/409\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}