{"id":407,"date":"2023-02-25T10:52:15","date_gmt":"2023-02-25T02:52:15","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=407"},"modified":"2023-04-29T21:36:36","modified_gmt":"2023-04-29T13:36:36","slug":"android-ndk-basic-c-typedef-consortium-enumeration","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/android-ndk-basic-c-typedef-consortium-enumeration\/","title":{"rendered":"Android NDK\u57fa\u78407\uff1aC_typedef_\u8054\u5408\u4f53_\u679a\u4e3e"},"content":{"rendered":"<h2>typedef \u7c7b\u578b\u53d6\u522b\u540d<\/h2>\n<pre><code class=\"language-c\">\/\/typedef \u7c7b\u578b\u53d6\u522b\u540d\n\/\/1.\u4e0d\u540c\u540d\u79f0\u4ee3\u8868\u5728\u5e72\u4e0d\u540c\u7684\u4e8b\u60c5typedef int jint;  \n\/\/2.\u4e0d\u540c\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u4e0d\u540c\u7684\u522b\u540d\n\/*\n#if defined(__cplusplus)\ntypedef _JNIEnv JNIEnv;\ntypedef _JavaVM JavaVM;\n#else\ntypedef const struct JNINatuveInterface* JNIEnv;\ntypedef const struct JNIInvokeInterface* JavaVM;\n#endif\n*\/\n\/\/3.\u4e66\u5199\u7b80\u6d01\n\nstruct Man {\n    char name[20];\n    int age;\n};\n\n\/\/Age int\u7c7b\u578b\u7684\u522b\u540d\ntypedef int size;\n\/\/Age int\u7c7b\u578b\u6307\u9488\u7684\u522b\u540d\ntypedef int* size_p;\n\n\/\/\u7ed3\u6784\u4f53\u53d6\u522b\u540d\ntypedef struct Man Man;\ntypedef struct Man* ManP;\n\n\/\/typedef struct Woman W;\n\/\/typedef struct Woman* WP;\n\n\/\/\u7b80\u5199\ntypedef struct Woman {\n    char name[20];\n    int age;\n} W, *WP;  \/\/W \u662fwoman\u7ed3\u6784\u4f53\u7684\u522b\u540d, WP \u662fwoman\u7ed3\u6784\u4f53\u6307\u9488\u7684\u522b\u540d\n\nvoid main() {\n    size i = 5;\n    size_p p = &amp;i;\n\n    \/\/\u7ed3\u6784\u4f53\u53d8\u91cf\n    W w = {&quot;Rose&quot;, 20};\n    \/\/\u7ed3\u6784\u4f53\u6307\u9488\n    WP wp = &amp;w;\n    printf(&quot;%s,%d\\n&quot;, w.name, w.age);\n    printf(&quot;%s,%d\\n&quot;, wp-&gt;name, wp-&gt;age);\n\n    getchar();\n}<\/code><\/pre>\n<p><!-- more --><\/p>\n<h2>\u8054\u5408\u4f53\uff08\u5171\u7528\u4f53\uff09<\/h2>\n<pre><code class=\"language-c\">\/\/\u8054\u5408\u4f53\uff08\u5171\u7528\u4f53\uff09\n\/\/\u4e0d\u540c\u7c7b\u578b\u7684\u53d8\u91cf\u5171\u540c\u5360\u7528\u4e00\u6bb5\u5185\u5b58\uff08\u76f8\u4e92\u8986\u76d6\uff09\uff0c\u8054\u5408\u53d8\u91cf\u4efb\u4f55\u65f6\u523b\u53ea\u6709\u4e00\u4e2a\u6210\u5458\u5b58\u5728\uff0c\u8282\u7701\u5185\u5b58\n\/\/\u8054\u5408\u4f53\u53d8\u91cf\u7684\u5927\u5c0f=\u6700\u5927\u7684\u6210\u5458\u6240\u5360\u7684\u5b57\u8282\u6570\n\/\/\u6bd4\u55bb\uff1a\u540c\u7a7f\u4e00\u6761\u88e4\u5b50\nunion MyValue {\n    int x;\n    int y;\n    double z;\n};\n\nvoid main() {\n    union MyValue d;\n    d.x = 90;\n    d.y = 100;  \/\/\u6700\u540e\u4e00\u6b21\u8d4b\u503c\u6709\u6548\n    \/\/d.z = 23.8;\n\n    printf(&quot;%d,%d,%lf\\n&quot;, d.x, d.y, d.z);\n    system(&quot;pause&quot;);\n}<\/code><\/pre>\n<pre><code class=\"language-c\">typedef union jvalue {\n    jboolean    z;\n    jbyte       b;\n    jchar       c;\n    jshort      s;\n    jint        i;\n    jlong       j;\n    jfloat      f;\n    jdouble     d;\n    jobject     l;\n} jvalue;<\/code><\/pre>\n<h2>\u679a\u4e3e<\/h2>\n<pre><code class=\"language-c\">\/\/\u679a\u4e3e\uff08\u5217\u4e3e\u6240\u6709\u7684\u60c5\u51b5\uff09\n\/\/\u9650\u5b9a\u503c\uff0c\u4fdd\u8bc1\u53d6\u503c\u7684\u5b89\u5168\u6027\n\/\/enumeration\n\/\/enum Day\n\/\/{\n\/\/    Monday = 0,\n\/\/    Tuesday = 1,\n\/\/    Wednesday = 2,\n\/\/    Thursday = 3,\n\/\/    Friday = 4,\n\/\/    Saturday = 5,\n\/\/    Sunday = 6\n\/\/};\n\/*\nenum Day\n{\n    Monday,\n    Tuesday,\n    Wednesday,\n    Thursday,\n    Friday,\n    Saturday,\n    Sunday\n};\n\nvoid main() {\n    \/\/\u679a\u4e3e\u7684\u503c\uff0c\u5fc5\u987b\u662f\u62ec\u53f7\u4e2d\u7684\u503c\n    \/\/\u679a\u4e3e\u7684\u503c\uff0c\u5728\u5185\u5b58\u7a7a\u95f4\u4e0a\u662f\u4e0d\u8fde\u7eed\u7684\n    enum Day d = Monday;\n    printf(&quot;%#x,%d\\n&quot;, &amp;d, d);\n\n    getchar();\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>typedef \u7c7b\u578b\u53d6\u522b\u540d \/\/typedef \u7c7b\u578b\u53d6\u522b\u540d \/\/1.\u4e0d\u540c\u540d\u79f0\u4ee3\u8868\u5728\u5e72\u4e0d\u540c\u7684\u4e8b\u60c5typedef  [&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-407","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\/407","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=407"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/407\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}