{"id":349,"date":"2020-11-03T11:12:40","date_gmt":"2020-11-03T15:12:40","guid":{"rendered":"http:\/\/www.prglab.com\/blog\/?page_id=349"},"modified":"2020-11-03T11:12:40","modified_gmt":"2020-11-03T15:12:40","slug":"user-defined-data-types","status":"publish","type":"page","link":"https:\/\/www.prglab.com\/blog\/cplusplus-tutorial\/compound-data\/user-defined-data-types","title":{"rendered":"\u81ea\u5b9a\u4e49\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"\n<h2>3.6 \u81ea\u5b9a\u4e49\u6570\u636e\u7c7b\u578b \uff08User defined data types\uff09<\/h2>\n\n\n\n<p>\u524d\u9762\u6211\u4eec\u5df2\u7ecf\u770b\u5230\u8fc7\u4e00\u79cd\u7528\u6237\uff08\u7a0b\u5e8f\u5458\uff09\u5b9a\u4e49\u7684\u6570\u636e\u7c7b\u578b\uff1a\u7ed3\u6784\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u5b83\u7c7b\u578b\u7684\u7528\u6237\u81ea\u5b9a\u4e49\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n\n\n\n<h3>\u5b9a\u4e49\u81ea\u5df1\u7684\u6570\u636e\u7c7b\u578b (typedef)<\/h3>\n\n\n\n<p>C++ \u5141\u8bb8\u6211\u4eec\u5728\u73b0\u6709\u6570\u636e\u7c7b\u578b\u7684\u57fa\u7840\u4e0a\u5b9a\u4e49\u6211\u4eec\u81ea\u5df1\u7684\u6570\u636e\u7c7b\u578b\u3002\u6211\u4eec\u5c06\u7528\u5173\u952e\u5b57typedef\u6765\u5b9e\u73b0\u8fd9\u79cd\u5b9a\u4e49\uff0c\u5b83\u7684\u5f62\u5f0f\u662f\uff1a<\/p>\n\n\n\n<p><code>typedef existing_type new_type_name;<\/code><\/p>\n\n\n\n<p>\u8fd9\u91cc existing_type \u662fC++ \u57fa\u672c\u6570\u636e\u7c7b\u578b\u6216\u5176\u5b83\u5df2\u7ecf\u88ab\u5b9a\u4e49\u4e86\u7684\u6570\u636e\u7c7b\u578b\uff0cnew_type_name \u662f\u6211\u4eec\u5c06\u8981\u5b9a\u4e49\u7684\u65b0\u6570\u636e\u7c7b\u578b\u7684\u540d\u79f0\u3002\u4f8b\u5982\uff1atypedef char C;<br>typedef unsigned int WORD;<br>typedef char * string_t;<br>typedef char field [50];<\/p>\n\n\n\n<p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u56db\u79cd\u65b0\u7684\u6570\u636e\u7c7b\u578b\uff1a C, WORD, string_t \u548c field \uff0c\u5b83\u4eec\u5206\u522b\u4ee3\u66ff char, unsigned int, char* \u548c char[50] \u3002\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5b89\u5168\u7684\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1aC achar, anotherchar, *ptchar1;<br>WORD myword;<br>string_t ptchar2;<br>field name;<\/p>\n\n\n\n<p>\u5982\u679c\u5728\u4e00\u4e2a\u7a0b\u5e8f\u4e2d\u6211\u4eec\u53cd\u590d\u4f7f\u7528\u4e00\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u800c\u5728\u4ee5\u540e\u7684\u7248\u672c\u4e2d\u6211\u4eec\u6709\u53ef\u80fd\u6539\u53d8\u8be5\u6570\u636e\u7c7b\u578b\u7684\u60c5\u51b5\u4e0b\uff0ctypedef \u5c31\u5f88\u6709\u7528\u4e86\u3002\u6216\u8005\u5982\u679c\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u7684\u540d\u79f0\u592a\u957f\uff0c\u4f60\u60f3\u7528\u4e00\u4e2a\u6bd4\u8f83\u77ed\u7684\u540d\u5b57\u6765\u4ee3\u66ff\uff0c\u4e5f\u53ef\u4ee5\u662f\u7528typedef\u3002<\/p>\n\n\n\n<h3>\u8054\u5408(Union)<\/h3>\n\n\n\n<p>\u8054\u5408(Union) \u4f7f\u5f97\u540c\u4e00\u6bb5\u5185\u5b58\u53ef\u4ee5\u88ab\u6309\u7167\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u6765\u8bbf\u95ee\uff0c\u6570\u636e\u5b9e\u9645\u662f\u5b58\u50a8\u5728\u540c\u4e00\u4e2a\u4f4d\u7f6e\u7684\u3002\u5b83\u7684\u58f0\u660e\u548c\u4f7f\u7528\u770b\u8d77\u6765\u4e0e\u7ed3\u6784(structure)\u5341\u5206\u76f8\u4f3c\uff0c\u4f46\u5b9e\u9645\u529f\u80fd\u662f\u5b8c\u5168\u4e0d\u540c\u7684\uff1aunion model_name {<br>&nbsp;&nbsp;&nbsp; type1 element1;<br>&nbsp;&nbsp;&nbsp; type2 element2;<br>&nbsp;&nbsp;&nbsp; type3 element3;<br>&nbsp;&nbsp;&nbsp; .<br>&nbsp;&nbsp;&nbsp; .<br>} object_name;<\/p>\n\n\n\n<p>union \u4e2d\u7684\u6240\u6709\u88ab\u58f0\u660e\u7684\u5143\u7d20\u5360\u636e\u540c\u4e00\u6bb5\u5185\u5b58\u7a7a\u95f4\uff0c\u5176\u5927\u5c0f\u53d6\u58f0\u660e\u4e2d\u6700\u957f\u7684\u5143\u7d20\u7684\u5927\u5c0f\u3002\u4f8b\u5982\uff1aunion mytypes_t {<br>&nbsp;&nbsp;&nbsp; char c;<br>&nbsp;&nbsp;&nbsp; int i;<br>&nbsp;&nbsp;&nbsp; float f;<br>} mytypes;<\/p>\n\n\n\n<p>\u5b9a\u4e49\u4e863\u4e2a\u5143\u7d20\uff1a<\/p>\n\n\n\n<p><code>mytypes.c<br>mytypes.i<br>mytypes.f<\/code><\/p>\n\n\n\n<p>\u6bcf\u4e00\u4e2a\u662f\u4e00\u79cd\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002\u65e2\u7136\u5b83\u4eec\u90fd\u6307\u5411\u540c\u4e00\u6bb5\u5185\u5b58\u7a7a\u95f4\uff0c\u6539\u53d8\u5176\u4e2d\u4e00\u4e2a\u5143\u7d20\u7684\u503c\uff0c\u5c06\u4f1a\u5f71\u54cd\u6240\u6709\u5176\u4ed6\u5143\u7d20\u7684\u503c\u3002<\/p>\n\n\n\n<p>union \u7684\u7528\u9014\u4e4b\u4e00\u662f\u5c06\u4e00\u79cd\u8f83\u957f\u7684\u57fa\u672c\u7c7b\u578b\u4e0e\u7531\u5176\u5b83\u6bd4\u8f83\u5c0f\u7684\u6570\u636e\u7c7b\u578b\u7ec4\u6210\u7684\u7ed3\u6784(structure)\u6216\u6570\u7ec4(array)\u8054\u5408\u4f7f\u7528\uff0c\u4f8b\u5982\uff1aunion mix_t{<br>&nbsp;&nbsp;&nbsp; long l;<br>&nbsp;&nbsp;&nbsp; struct {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; short hi;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; short lo;<br>&nbsp;&nbsp;&nbsp; } s;<br>&nbsp;&nbsp;&nbsp; char c[4];<br>} mix;<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u4f8b\u5b50\u4e2d\u5b9a\u4e49\u4e863\u4e2a\u540d\u79f0\uff1amix.l, mix.s \u548c mix.c\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8fd93\u4e2a\u540d\u5b57\u6765\u8bbf\u95ee\u540c\u4e00\u6bb54 bytes\u957f\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u81f3\u4e8e\u4f7f\u7528\u54ea\u4e00\u4e2a\u540d\u5b57\u6765\u8bbf\u95ee\uff0c\u53d6\u51b3\u4e8e\u6211\u4eec\u60f3\u4f7f\u7528\u4ec0\u4e48\u6570\u636e\u7c7b\u578b\uff0c\u662flong, short \u8fd8\u662f char \u3002\u4e0b\u56fe\u663e\u793a\u4e86\u5728\u8fd9\u4e2a\u8054\u5408(union)\u4e2d\u5404\u4e2a\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u7684\u7684\u53ef\u80fd\u7ed3\u6784\uff0c\u4ee5\u53ca\u6211\u4eec\u5982\u4f55\u901a\u8fc7\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u8fdb\u884c\u8bbf\u95ee\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/www.prglab.com\/cms\/media\/images\/cplusplus\/img3-6-1.gif\" alt=\"\"\/><\/figure>\n\n\n\n<h3>\u533f\u540d\u8054\u5408(Anonymous union)<\/h3>\n\n\n\n<p><img src=\"http:\/\/www.prglab.com\/cms\/media\/images\/cplusplus\/c-diff.png\" alt=\"\">\u5728 C++ \u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u4f7f\u8054\u5408(union)\u533f\u540d\u3002\u5982\u679c\u6211\u4eec\u5c06\u4e00\u4e2aunion\u5305\u62ec\u5728\u4e00\u4e2a\u7ed3\u6784(structure)\u7684\u5b9a\u4e49\u4e2d\uff0c\u5e76\u4e14\u4e0d\u8d4b\u4e88\u5b83object\u540d\u79f0 (\u5c31\u662f\u8ddf\u5728\u82b1\u62ec\u53f7{}\u540e\u9762\u7684\u540d\u5b57)\uff0c\u8fd9\u4e2aunion\u5c31\u662f\u533f\u540d\u7684\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528union\u4e2d\u5143\u7d20\u7684\u540d\u5b57\u6765\u8bbf\u95ee\u8be5\u5143\u7d20\uff0c\u800c\u4e0d\u9700\u8981\u518d\u5728\u524d\u9762\u52a0 union\u5bf9\u8c61\u7684\u540d\u79f0\u3002\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u8fd9\u4e24\u79cd\u8868\u8fbe\u65b9\u5f0f\u5728\u4f7f\u7528\u4e0a\u7684\u533a\u522b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>union<\/th><th>anonymous union<\/th><\/tr><tr><td>struct {<br>&nbsp;&nbsp;&nbsp; char title[50];<br>&nbsp;&nbsp;&nbsp; char author[50];<br>&nbsp;&nbsp;&nbsp; union {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float dollars;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int yens;<br>&nbsp;&nbsp;&nbsp; } price;<br>} book;<\/td><td>struct {<br>&nbsp;&nbsp;&nbsp; char title[50];<br>&nbsp;&nbsp;&nbsp; char author[50];<br>&nbsp;&nbsp;&nbsp; union {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float dollars;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int yens;<br>&nbsp;&nbsp;&nbsp; };<br>} book;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ee5\u4e0a\u4e24\u79cd\u5b9a\u4e49\u7684\u552f\u4e00\u533a\u522b\u5728\u4e8e\u5de6\u8fb9\u7684\u5b9a\u4e49\u4e2d\u6211\u4eec\u7ed9\u4e86union\u4e00\u4e2a\u540d\u5b57price\uff0c\u800c\u5728\u53f3\u8fb9\u7684\u5b9a\u4e49\u4e2d\u6211\u4eec\u6ca1\u7ed9\u3002\u5728\u4f7f\u7528\u65f6\u7684\u533a\u522b\u662f\u5f53\u6211\u4eec\u60f3\u8bbf\u95ee\u4e00\u4e2a\u5bf9\u8c61(object)\u7684\u5143\u7d20dollars \u548cyens \u65f6\uff0c\u5728\u524d\u4e00\u79cd\u5b9a\u4e49\u7684\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u4f7f\u7528\uff1a<\/p>\n\n\n\n<p><code>book.price.dollars<br>book.price.yens<\/code><\/p>\n\n\n\n<p>\u800c\u5728\u540e\u9762\u4e00\u79cd\u5b9a\u4e49\u4e0b\uff0c\u6211\u4eec\u76f4\u63a5\u4f7f\u7528\uff1a<\/p>\n\n\n\n<p><code>book.dollars<br>book.yens<\/code><\/p>\n\n\n\n<p>\u518d\u4e00\u6b21\u63d0\u9192\uff0c\u56e0\u4e3a\u8fd9\u662f\u4e00\u4e2a\u8054\u5408(union)\uff0c\u57dfdollars \u548cyens \u5360\u636e\u7684\u662f\u540c\u4e00\u5757\u5185\u5b58\u7a7a\u95f4\uff0c\u6240\u4ee5\u5b83\u4eec\u4e0d\u80fd\u88ab\u7528\u6765\u5b58\u50a8\u4e24\u4e2a\u4e0d\u540c\u7684\u503c\u3002\u4e5f\u5c31\u662f\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2adollars \u6216yens\u7684\u4ef7\u683c\uff0c\u4f46\u4e0d\u80fd\u540c\u65f6\u4f7f\u7528\u4e24\u8005\u3002<\/p>\n\n\n\n<h3>\u679a\u4e3eEnumerations (enum)<\/h3>\n\n\n\n<p>\u679a\u4e3e(Enumerations)\u53ef\u4ee5\u7528\u6765\u751f\u6210\u4e00\u4e9b\u4efb\u610f\u7c7b\u578b\u7684\u6570\u636e\uff0c\u4e0d\u53ea\u9650\u4e8e\u6570\u5b57\u7c7b\u578b\u6216\u5b57\u7b26\u7c7b\u578b\uff0c\u751a\u81f3\u5e38\u91cftrue \u548cfalse\u3002\u5b83\u7684\u5b9a\u4e49\u5f62\u5f0f\u5982\u4e0b\uff1aenum model_name {<br>&nbsp;&nbsp;&nbsp; value1,<br>&nbsp;&nbsp;&nbsp; value2,<br>&nbsp;&nbsp;&nbsp; value3,<br>&nbsp;&nbsp;&nbsp; .<br>&nbsp;&nbsp;&nbsp; .<br>} object_name;<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4e00\u79cd\u65b0\u7684\u53d8\u91cf\u7c7b\u578b\u53eb\u505acolor_t \u6765\u5b58\u50a8\u4e0d\u540c\u7684\u989c\u8272\uff1a<\/p>\n\n\n\n<p><code>enum colors_t {black, blue, green, cyan, red, purple, yellow, white};<\/code><\/p>\n\n\n\n<p>\u6ce8\u610f\u5728\u8fd9\u4e2a\u5b9a\u4e49\u91cc\u6211\u4eec\u6ca1\u6709\u4f7f\u7528\u4efb\u4f55\u57fa\u672c\u6570\u636e\u7c7b\u578b\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u6211\u4eec\u521b\u9020\u4e86\u4e00\u79cd\u7684\u65b0\u7684\u6570\u636e\u7c7b\u578b\uff0c\u800c\u5b83\u5e76\u6ca1\u6709\u57fa\u4e8e\u4efb\u4f55\u5df2\u5b58\u5728\u7684\u6570\u636e\u7c7b\u578b\uff1a\u7c7b\u578bcolor_t\uff0c\u82b1\u62ec\u53f7{}\u4e2d\u5305\u62ec\u4e86\u5b83\u7684\u6240\u6709\u7684\u53ef\u80fd\u53d6\u503c\u3002\u4f8b\u5982\uff0c\u5728\u5b9a\u4e49\u4e86colors_t \u5217\u4e3e\u7c7b\u578b\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8868\u8fbe\u5f0f \uff1acolors_t mycolor;<br>mycolor = blue;<br>if (mycolor == green) mycolor = red;<\/p>\n\n\n\n<p>\u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u7684\u679a\u4e3e\u6570\u636e\u7c7b\u578b\u5728\u7f16\u8bd1\u65f6\u662f\u88ab\u7f16\u8bd1\u4e3a\u6574\u578b\u6570\u503c\u7684\uff0c\u800c\u5b83\u7684\u6570\u503c\u5217\u8868\u53ef\u4ee5\u662f\u4efb\u4f55\u6307\u5b9a\u7684\u6574\u578b\u5e38\u91cf \u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u5e38\u91cf\uff0c\u679a\u4e3e\u4e2d\u7b2c\u4e00\u4e2a\u5217\u51fa\u7684\u53ef\u80fd\u503c\u4e3a0 \uff0c\u540e\u9762\u7684\u6bcf\u4e00\u4e2a\u503c\u4e3a\u524d\u9762\u4e00\u4e2a\u503c\u52a01\u3002\u56e0\u6b64\uff0c\u5728\u6211\u4eec\u524d\u9762\u5b9a\u4e49\u7684\u6570\u636e\u7c7b\u578bcolors_t \u4e2d\uff0cblack \u76f8\u5f53\u4e8e0\uff0c blue \u76f8\u5f53\u4e8e 1\uff0c green \u76f8\u5f53\u4e8e2 \uff0c\u540e\u9762\u4f9d\u6b64\u7c7b\u63a8\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u5728\u5b9a\u4e49\u679a\u4e3e\u6570\u636e\u7c7b\u578b\u7684\u65f6\u5019\u660e\u786e\u6307\u5b9a\u67d0\u4e9b\u53ef\u80fd\u503c\uff08\u4f8b\u5982\u7b2c\u4e00\u4e2a\uff09\u7684\u7b49\u4ef7\u6574\u6570\u503c\uff0c\u540e\u9762\u7684\u6570\u503c\u5c06\u4f1a\u5728\u6b64\u57fa\u7840\u4e0a\u589e\u52a0\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">enum months_t { january=1, february, march, april,<br>                may, june, july, august,<br>                september, october, november, december} y2k;<\/pre>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u679a\u4e3e\u7c7b\u578bmonths_t\u7684\u53d8\u91cfy2k \u53ef\u4ee5\u662f12\u79cd\u53ef\u80fd\u53d6\u503c\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\uff0c\u4ecejanuary \u5230 december \uff0c\u5b83\u4eec\u76f8\u5f53\u4e8e\u6570\u503c1 \u5230 12\uff0c\u800c\u4e0d\u662f0 \u5230 11 \uff0c\u56e0\u4e3a\u6211\u4eec\u5df2\u7ecf\u6307\u5b9a january \u7b49\u4e8e1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>3.6 \u81ea\u5b9a\u4e49\u6570\u636e\u7c7b\u578b \uff08User defined data types\uff09 \u524d\u9762\u6211\u4eec\u5df2\u7ecf\u770b\u5230\u8fc7\u4e00\u79cd\u7528\u6237\uff08\u7a0b\u5e8f\u5458\uff09\u5b9a\u4e49\u7684\u6570\u636e\u7c7b\u578b\uff1a\u7ed3\u6784\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u5b83\u7c7b\u578b\u7684\u7528\u6237\u81ea\u5b9a\u4e49\u6570\u636e\u7c7b\u578b\uff1a \u5b9a\u4e49\u81ea\u5df1\u7684\u6570\u636e\u7c7b\u578b (typedef) C++ \u5141\u8bb8\u6211\u4eec\u5728\u73b0\u6709\u6570\u636e\u7c7b\u578b\u7684\u57fa\u7840\u4e0a\u5b9a\u4e49\u6211\u4eec\u81ea\u5df1\u7684\u6570\u636e\u7c7b\u578b\u3002\u6211\u4eec\u5c06\u7528\u5173\u952e\u5b57typedef\u6765\u5b9e\u73b0\u8fd9\u79cd\u5b9a\u4e49\uff0c\u5b83\u7684\u5f62\u5f0f\u662f\uff1a typedef existing_type new_type_name; \u8fd9\u91cc existing_type \u662fC++ \u57fa\u672c\u6570\u636e\u7c7b\u578b\u6216\u5176\u5b83\u5df2\u7ecf\u88ab\u5b9a\u4e49\u4e86\u7684\u6570\u636e\u7c7b\u578b\uff0cnew_type_name \u662f\u6211\u4eec\u5c06\u8981\u5b9a\u4e49\u7684\u65b0\u6570\u636e\u7c7b\u578b\u7684\u540d\u79f0\u3002\u4f8b\u5982\uff1atypedef char C;typedef unsigned int WORD;typedef char * string_t;typedef char field [50]; \u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u56db\u79cd\u65b0\u7684\u6570\u636e\u7c7b\u578b\uff1a C, WORD, string_t \u548c field \uff0c\u5b83\u4eec\u5206\u522b\u4ee3\u66ff char, unsigned int, char* \u548c char[50] \u3002\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5b89\u5168\u7684\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1aC achar, anotherchar, *ptchar1;WORD myword;string_t ptchar2;field name; \u5982\u679c\u5728\u4e00\u4e2a\u7a0b\u5e8f\u4e2d\u6211\u4eec\u53cd\u590d\u4f7f\u7528\u4e00\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u800c\u5728\u4ee5\u540e\u7684\u7248\u672c\u4e2d\u6211\u4eec\u6709\u53ef\u80fd\u6539\u53d8\u8be5\u6570\u636e\u7c7b\u578b\u7684\u60c5\u51b5\u4e0b\uff0ctypedef \u5c31\u5f88\u6709\u7528\u4e86\u3002\u6216\u8005\u5982\u679c\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u7684\u540d\u79f0\u592a\u957f\uff0c\u4f60\u60f3\u7528\u4e00\u4e2a\u6bd4\u8f83\u77ed\u7684\u540d\u5b57\u6765\u4ee3\u66ff\uff0c\u4e5f\u53ef\u4ee5\u662f\u7528typedef\u3002 \u8054\u5408(Union) \u8054\u5408(Union) \u4f7f\u5f97\u540c\u4e00\u6bb5\u5185\u5b58\u53ef\u4ee5\u88ab\u6309\u7167\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u6765\u8bbf\u95ee\uff0c\u6570\u636e\u5b9e\u9645\u662f\u5b58\u50a8\u5728\u540c\u4e00\u4e2a\u4f4d\u7f6e\u7684\u3002\u5b83\u7684\u58f0\u660e\u548c\u4f7f\u7528\u770b\u8d77\u6765\u4e0e\u7ed3\u6784(structure)\u5341\u5206\u76f8\u4f3c\uff0c\u4f46\u5b9e\u9645\u529f\u80fd\u662f\u5b8c\u5168\u4e0d\u540c\u7684\uff1aunion [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":335,"menu_order":5,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/349"}],"collection":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/comments?post=349"}],"version-history":[{"count":1,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/349\/revisions"}],"predecessor-version":[{"id":350,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/349\/revisions\/350"}],"up":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/335"}],"wp:attachment":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/media?parent=349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}