{"id":242,"date":"2023-02-22T01:39:33","date_gmt":"2023-02-22T09:39:33","guid":{"rendered":"http:\/\/bitas.net.cn\/?page_id=242"},"modified":"2023-02-22T01:39:33","modified_gmt":"2023-02-22T09:39:33","slug":"068-2","status":"publish","type":"page","link":"http:\/\/bitas.net.cn\/index.php\/sourcecode\/068-2\/","title":{"rendered":"068 \u5185\u5b58\u5b58\u53d6\u8fd0\u7b97\u7b26"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n\nstruct object {\n    int inArray;\n    union ID {\n        int index;\n        void * address;\n    } id; \n};\n\ntypedef int (*f_init)(struct object *obj, int inx, void * addr);\ntypedef void (*f_report)(const struct object *obj);\n\nint object_init(struct object *obj, int inx, void * addr)\n{\n    if (obj) {\n        if (obj->inArray)\n            obj->id.index = inx;\n        else\n            obj->id.address = addr;\n        return 1;\n    }   \n    else\n        return 0;\n}\n\nvoid object_report(const struct object *obj)\n{\n    if (obj) {\n        if ((*obj).inArray)\n            printf(\"object index: %d.\\n\", (*obj).id.index);\n        else\n            printf(\"object address: %p.\\n\", (*obj).id.address);\n    }   \n}\n\nint main(int argc, char *argv&#91;])\n{\n    struct object single_obj, obj_arr&#91;2];\n    f_init init = object_init;\n    f_report report = object_report;\n\n    single_obj.inArray = 0;\n    (void)(*init)(&amp;single_obj, -1, &amp;single_obj);\n    report(&amp;single_obj);\n\n    obj_arr&#91;0] = single_obj;\n    0&#91;obj_arr].inArray = 1;\n    (void)(*init)(obj_arr, 0, NULL);\n    report(obj_arr);\n\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":127,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-242","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/comments?post=242"}],"version-history":[{"count":1,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/242\/revisions"}],"predecessor-version":[{"id":243,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/242\/revisions\/243"}],"up":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/127"}],"wp:attachment":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/media?parent=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}