Knowledge (XXG)

Union type

Source 📝

47: 1031:, which is still accepted as a synonym for union by several compilers. The union declaration is similar to the structure definition, where elements at the same level within the union declaration occupy the same storage. Elements of the union can be any data type, including structures and array. Here vers_num and vers_bytes occupy the same storage locations. 770:, there are two ways to create unions. One is the standard way through a variant record. The second is a nonstandard means of declaring a variable as absolute, meaning it is placed at the same memory location as another variable or at an absolute address. While all Pascal compilers support variant records, only some support absolute variables. 428:, and as a non-standard extension in many compilers, unions can also be anonymous. Their data members do not need to be referenced, are instead accessed directly. They have some restrictions as opposed to traditional unions: in C11, they must be a member of another structure or union, and in C++, they can not have 2170:
The scheme of type composition adopted by C owes considerable debt to Algol 68, although it did not, perhaps, emerge in a form that Algol's adherents would approve of. The central notion I captured from Algol was a type structure based on atomic types (including structures), composed into arrays,
264:
However, one useful programming function of unions is to map smaller data elements to larger ones for easier manipulation. A data structure consisting, for example, of 4 bytes and a 32-bit integer, can form a union with an unsigned 64-bit integer, and thus be more readily accessed for purposes of
578:
attribute is available for union types. Types contained in the union can be converted transparently to the union type itself in a function call, provided that all types have the same size. It is mainly intended for function with multiple parameter interfaces, a use necessitated by early Unix
281:
has tagged unions, and uses a case clause to distinguish and extract the constituent type at runtime. A union containing another union is treated as the set of all its constituent possibilities, and if the context requires it a union is automatically coerced into the wider union. A union can
260:
of its constituting types, since it can take on any value any of its fields can. Also, because a mathematical union discards duplicates, if more than one field of the union can take on a single common value, it is impossible to tell from the value alone which field was last written.
388:. However, there is no checking of types, so it is up to the programmer to be sure that the proper fields are accessed in different contexts. The relevant field of a union variable is typically determined by the state of other variables, possibly in an enclosing struct. 198:
A union can be pictured as a chunk of memory that is used to store variables of different data types. Once a new value is assigned to a field, the existing data is overwritten with the new data. The memory area storing the value has no intrinsic type (other than just
714:
over the first item, the two items share the same address in memory, and therefore share the same underlying data bytes. The first item interprets the two data bytes as a binary value, while the second item interprets the bytes as character values.
1715:
comparison for complex data types. Types with overlapping usage (e.g. a slice method exists on both strings and arrays, the plus operator works on both strings and numbers) don't need additional narrowing to use these features.
373:) also allows for a data member to be any type that has a full-fledged constructor/destructor and/or copy constructor, or a non-trivial copy assignment operator. For example, it is possible to have the standard C++ 369:), except that each data member is located at the same memory address. The data members, as in structures, need not be primitive values, and in fact may be structures or even other unions. C++ (since 435:
Simply omitting the class-name portion of the syntax does not make a union an anonymous union. For a union to qualify as an anonymous union, the declaration must not declare an object. Example:
852:
In the first example, each of the elements of the array B maps to one of the specific bytes of the variable A. In the second example, the variable C is assigned to the exact machine address 0.
405:
Structure and union specifiers have the same form. The size of a union is sufficient to contain the largest of its members. The value of at most one of the members can be stored in a union
1074:
An alternative to a union declaration is the DEFINED attribute, which allows alternative declarations of storage, however the data types of the base and defined variables must match.
409:
at any time. A pointer to a union object, suitably converted, points to each of its members (or if a member is a bit-field, then to the unit in which it resides), and vice versa.
595:(66 level) keyword, which effectively maps a second alphanumeric data item on top of the same memory location as a preceding data item. In the example code below, data item 1095:
in most other languages, enum variants in Rust can contain additional data in the form of a tuple or struct, making them tagged unions rather than simple enumerated types.
397:, by assigning to one field of a union and reading from another, as is done in code which depends on the raw representation of the values. A practical example is the 233:
and comparison for equality, without knowing its specific type. Other operations may require that knowledge, either by some external information, or by the use of a
380:
The primary use of a union is allowing access to a common location by different data types, for example hardware input/output access, bitfield and word sharing, or
1116:
function or block, as the compiler cannot guarantee that the data in the union will be valid for the type of the field; if this is not the case, it will result in
2902: 3069: 2578: 3440: 3074: 3064: 3059: 2872: 1491:
Union types were introduced in PHP 8.0. The values are implicitly "tagged" with a type by the language, and may be retrieved by "gettype()".
2222: 3047: 2948: 245:
Because of the limitations of their use, untagged unions are generally only provided in untyped languages or in a type-unsafe way (as in
2510: 1707:
Union types are supported in TypeScript. The values are implicitly "tagged" with a type by the language, and may be retrieved using a
1110:
attribute will be laid out in memory exactly like the equivalent union in C. Reading the fields of a union can only be done within an
2539: 3501: 2811: 2171:
pointers (references), and functions (procedures). Algol 68's concept of unions and casts also had an influence that appeared later.
398: 130: 3198: 2601: 385: 366: 3315: 3120: 3052: 3014: 2606: 68: 3496: 2571: 767: 429: 111: 3215: 3145: 2993: 204: 83: 3470: 2685: 2668: 1082: 160: 64: 3225: 3093: 2884: 2651: 2646: 2551: 349:
The syntax of the C/C++ union type and the notion of casts was derived from ALGOL 68, though in an untagged form.
90: 57: 3403: 3355: 3267: 3245: 3240: 3168: 3034: 2641: 425: 406: 188: 1605:
Support for typing was introduced in Python 3.5. The new syntax for union types were introduced in Python 3.10.
3277: 2941: 2680: 2675: 2634: 2564: 358: 246: 152: 2470: 3430: 3345: 2915: 2892: 2204: 97: 3173: 3029: 2988: 2983: 2897: 2697: 2298: 3163: 3138: 2823: 2778: 2740: 179:. In other words, a union type specifies the permitted types that may be stored in its instances, e.g., 168: 2241: 79: 249:). They have the advantage over simple tagged unions of not requiring space to store a data type tag. 2965: 2763: 2274:
Enterprise PL/I for z/OS PL/I for AIX IBM Developer for z Systems PL/I for windows Language Reference
230: 2346: 3491: 3435: 3413: 3340: 3193: 3185: 3105: 2934: 2806: 855:
In the following example, a record has variants, some of which share the same location as others:
3418: 3398: 3350: 3325: 3110: 3079: 2791: 2656: 2616: 2026: 1117: 257: 208: 31: 3305: 3235: 3210: 3024: 3019: 2725: 2624: 2506: 2502: 2495: 253: 2420: 1085:
implements both tagged and untagged unions. In Rust, tagged unions are implemented using the
3450: 3335: 3133: 2748: 2159: 393: 144: 1104:
keyword. The memory layout of unions in Rust is undefined by default, but a union with the
3455: 3320: 3272: 3205: 2768: 2710: 1092: 229:
Depending on the language and type, a union value may be used in some operations, such as
156: 2183: 252:
The name "union" stems from the type's formal definition. If a type is considered as the
2370: 2272: 374: 104: 17: 3408: 3230: 3220: 3128: 2860: 2838: 2663: 2587: 2322: 2143: 223: 164: 706:
is defined as a 2-byte binary integer containing a version number. A second data item
3485: 3330: 2833: 2730: 2715: 2029:
if the data in the union is not valid as the type of the field, and thus requires an
2122:// This results in undefined behavior, as the value stored in x is not a valid bool. 282:
explicitly contain no value, which can be distinguished at runtime. An example is:
3287: 3262: 381: 234: 2147: 256:
of all values that that type can take on, a union type is simply the mathematical
155:
that may have any of multiple representations or formats within the same area of
3465: 3460: 3310: 3257: 3084: 2828: 2753: 215: 46: 35: 3370: 3365: 3250: 3155: 3098: 2816: 2720: 710:
is defined as a two-character alphanumeric variable. Since the second item is
27:
Data type that allows for values that are one of multiple different data types
2395: 1272:
A structure can also be a member of a union, as the following example shows:
3445: 3423: 3380: 3375: 3042: 2998: 2957: 2758: 2705: 2445: 176: 2855: 2164: 3360: 2801: 2629: 2533: 773:
For the purposes of this example, the following are all integer types: a
278: 219: 211:, having the type of the value that was last written to the memory area. 599:
is defined as a group containing another group and a numeric data item.
370: 2850: 2796: 391:
One common C programming idiom uses unions to perform what C++ calls a
1367:(which in turn contains three members), and an integer variable named 2845: 2786: 2545: 2092:// This will set y to 10, and does not result in undefined behavior. 362: 2556: 1763:// types that support the same operations don't need narrowing 588: 607:, treating the data bytes continued within it as character data. 2978: 2867: 1024: 365:, untagged unions are expressed nearly exactly like structures ( 200: 2930: 2560: 1374:
Unions may occur within structures and arrays, and vice versa:
591:, union data items are defined in two ways. The first uses the 2973: 2421:"typing — Support for type hints — Python 3.9.7 documentation" 399:
method of computing square roots using the IEEE representation
40: 2926: 788:
The following example shows the non-standard absolute form:
207:
of memory), but the value can be treated as one of several
574:
In compilers such as GCC, Clang, and IBM XL C for AIX, a
401:. This is not, however, a safe use of unions in general. 2025:
Reading from the fields of an untagged union results in
414:
ANSI/ISO 9899:1990 (the ANSI C standard) Section 6.5.2.1
1359:), which contains two members, a structure (tagged as 698:
The second way to define a union type is by using the
2299:"How Rust Implements Tagged Unions - Pat Shaughnessy" 603:
is defined as an alphanumeric data item that renames
1923:
keyword, and can contain tuple and struct variants:
1475:
and the first character of string sval by either of
3389: 3298: 3184: 3154: 3119: 3007: 2964: 2883: 2777: 2739: 2696: 2615: 2594: 2030: 1981: 1918: 1111: 1105: 1099: 1086: 575: 195:an integer; a union would hold only one at a time. 71:. Unsourced material may be challenged and removed. 2494: 191:, which could be defined to contain both a float 2493:Kernighan, Brian W.; Ritchie, Dennis M. (1978). 518:"Hexadecimal representation of 3.14f:" 2446:"PEP 604 -- Allow writing union types as X | Y" 566:definitions to provide a sense of namespacing. 403: 702:keyword. In the example code below, data item 2942: 2572: 1098:Rust also supports untagged unions using the 8: 2548:, differences between union & structure 2243:IBM System/360 PL/I Language Specifications 2223:"Common Type Attributes: transparent_union" 2949: 2935: 2927: 2579: 2565: 2557: 2552:Difference between struct and union in C++ 2471:"Handbook - Unions and Intersection Types" 2184:"6.63 Unnamed Structure and Union Fields" 2163: 579:extensions and later re-standardisation. 131:Learn how and when to remove this message 2266: 2264: 2536:, a type-safe alternative to C++ unions 2501:(1st ed.). Prentice Hall. p.  2227:Using the GNU Compiler Collection (GCC) 2135: 269:Unions in various programming languages 2540:MSDN: Classes, Structures & Unions 562:Anonymous unions are also useful in C 384:. Unions can also provide low-level 339:): print(("void:", "EMPTY")), 7: 69:adding citations to reliable sources 2148:"The Development of the C Language" 2347:"Type layout - The Rust Reference" 2323:"Union types - The Rust Reference" 1471:The number ival is referred to as 1027:the original term for a union was 25: 1711:call for primitive values and an 1980:Untagged unions in Rust use the 1826:// distinct types need narrowing 1351:This example defines a variable 488:// Assumes float is 32 bits wide 45: 335:s): print(("string:", s)), ( 331:i): print(("int:", i)), ( 327:r): print(("real:", r)), ( 56:needs additional citations for 2240:IBM Corporation (March 1968). 1917:Tagged unions in Rust use the 1: 3015:Arbitrary-precision or bignum 2371:"Unions - The Rust Reference" 1133:In C and C++, the syntax is: 2271:IBM Corporation (Dec 2017). 2903:Directed acyclic word graph 2669:Double-ended priority queue 3518: 2497:The C Programming Language 29: 3356:Strongly typed identifier 2911: 2542:, for examples and syntax 3502:C (programming language) 2635:Retrieval Data Structure 2037: 1988: 1925: 1718: 1607: 1493: 1376: 1274: 1135: 1033: 857: 790: 717: 609: 437: 377:as a member of a union. 30:Not to be confused with 18:Union (computer science) 3431:Parametric polymorphism 2916:List of data structures 2893:Binary decision diagram 777:consists of 8 bits, a 2898:Directed acyclic graph 2475:www.typescriptlang.org 2396:"PHP 8.0: Union Types" 2205:"CUnionsForNamespaces" 1355:as a union (tagged as 432:or access specifiers. 417: 222:; this corresponds to 2165:10.1145/155360.155580 1901:// has to be a number 187:. In contrast with a 169:programming languages 163:that may hold such a 159:; that consists of a 3497:Composite data types 2764:Unrolled linked list 2394:Karunaratne, Ayesh. 2203:Siebenmann., Chris. 1889:// do something else 65:improve this article 3436:Primitive data type 3341:Recursive data type 3194:Algebraic data type 3070:Quadruple precision 2812:Self-balancing tree 2152:ACM SIGPLAN Notices 1069:pic '(2)A'; 781:is 16 bits, and an 209:abstract data types 3399:Abstract data type 3080:Extended precision 3039:Reduced precision 2792:Binary search tree 2657:Double-ended queue 2303:patshaughnessy.net 2144:Ritchie, Dennis M. 2027:undefined behavior 1880:"string" 1784:dependsOnParameter 1124:Syntax and example 1118:undefined behavior 343:print(("?:", n)) 315:n := "abc"; 32:Union (set theory) 3479: 3478: 3211:Associative array 3075:Octuple precision 2924: 2923: 2726:Hashed array tree 2625:Associative array 2375:doc.rust-lang.org 2351:doc.rust-lang.org 2327:doc.rust-lang.org 645:PERSON-NAME-FIRST 576:transparent_union 570:Transparent union 141: 140: 133: 115: 16:(Redirected from 3509: 3451:Type constructor 3336:Opaque data type 3268:Record or Struct 3065:Double precision 3060:Single precision 2951: 2944: 2937: 2928: 2749:Association list 2581: 2574: 2567: 2558: 2523: 2521: 2519: 2500: 2486: 2485: 2483: 2481: 2467: 2461: 2460: 2458: 2456: 2442: 2436: 2435: 2433: 2431: 2417: 2411: 2410: 2408: 2406: 2391: 2385: 2384: 2382: 2381: 2367: 2361: 2360: 2358: 2357: 2343: 2337: 2336: 2334: 2333: 2319: 2313: 2312: 2310: 2309: 2295: 2289: 2288: 2286: 2284: 2279: 2268: 2259: 2258: 2256: 2254: 2248: 2237: 2231: 2230: 2219: 2213: 2212: 2209:utcc.utoronto.ca 2200: 2194: 2193: 2191: 2190: 2180: 2174: 2173: 2167: 2140: 2123: 2120: 2117: 2114: 2111: 2108: 2105: 2102: 2099: 2096: 2093: 2090: 2087: 2084: 2081: 2078: 2075: 2072: 2069: 2066: 2063: 2060: 2056: 2053: 2050: 2047: 2044: 2041: 2034: 2033: 2021: 2018: 2015: 2011: 2008: 2005: 2001: 1998: 1995: 1992: 1985: 1984: 1976: 1973: 1970: 1966: 1963: 1960: 1956: 1953: 1950: 1947: 1944: 1941: 1938: 1935: 1932: 1929: 1922: 1921: 1908: 1905: 1902: 1899: 1896: 1893: 1890: 1887: 1884: 1881: 1878: 1875: 1872: 1869: 1866: 1863: 1860: 1857: 1854: 1851: 1848: 1845: 1842: 1839: 1836: 1833: 1830: 1827: 1824: 1821: 1818: 1815: 1812: 1809: 1806: 1803: 1800: 1797: 1794: 1791: 1788: 1785: 1782: 1779: 1776: 1773: 1770: 1767: 1764: 1761: 1758: 1755: 1752: 1749: 1746: 1743: 1740: 1737: 1734: 1731: 1728: 1725: 1722: 1714: 1710: 1698: 1695: 1692: 1689: 1686: 1683: 1680: 1677: 1674: 1671: 1668: 1665: 1662: 1659: 1656: 1653: 1650: 1647: 1644: 1641: 1638: 1635: 1632: 1629: 1626: 1623: 1620: 1617: 1614: 1611: 1596: 1593: 1590: 1587: 1584: 1581: 1578: 1575: 1572: 1569: 1566: 1563: 1560: 1557: 1554: 1551: 1548: 1545: 1542: 1539: 1536: 1533: 1530: 1527: 1524: 1521: 1518: 1515: 1512: 1509: 1506: 1503: 1500: 1497: 1482: 1478: 1474: 1467: 1464: 1461: 1458: 1455: 1452: 1449: 1446: 1443: 1440: 1437: 1434: 1431: 1428: 1425: 1422: 1419: 1416: 1413: 1410: 1407: 1404: 1401: 1398: 1395: 1392: 1389: 1386: 1383: 1380: 1370: 1366: 1362: 1358: 1354: 1347: 1344: 1341: 1338: 1335: 1332: 1329: 1326: 1323: 1320: 1317: 1314: 1311: 1308: 1305: 1302: 1299: 1296: 1293: 1290: 1287: 1284: 1281: 1278: 1268: 1265: 1262: 1259: 1256: 1253: 1250: 1247: 1244: 1241: 1238: 1235: 1232: 1229: 1226: 1223: 1220: 1217: 1214: 1211: 1208: 1205: 1202: 1199: 1196: 1193: 1190: 1187: 1184: 1181: 1178: 1175: 1172: 1169: 1166: 1163: 1160: 1157: 1154: 1151: 1148: 1145: 1142: 1139: 1115: 1114: 1109: 1108: 1103: 1102: 1093:enumerated types 1091:keyword. Unlike 1090: 1089: 1070: 1067: 1064: 1061: 1058: 1055: 1052: 1049: 1046: 1043: 1040: 1037: 1014: 1011: 1008: 1005: 1002: 999: 996: 993: 990: 987: 984: 981: 978: 975: 972: 969: 966: 963: 960: 957: 954: 951: 948: 945: 942: 939: 936: 933: 930: 927: 924: 921: 918: 915: 912: 909: 906: 903: 900: 897: 894: 891: 888: 885: 882: 879: 876: 873: 870: 867: 864: 861: 848: 845: 842: 839: 836: 833: 830: 827: 824: 821: 818: 815: 812: 809: 806: 803: 800: 797: 794: 757: 754: 751: 748: 745: 742: 739: 736: 733: 730: 727: 724: 721: 709: 705: 701: 694: 691: 688: 685: 682: 679: 676: 673: 670: 667: 664: 661: 658: 655: 652: 649: 646: 643: 640: 637: 634: 633:PERSON-NAME-LAST 631: 628: 625: 622: 619: 616: 613: 606: 602: 598: 594: 577: 565: 558: 555: 552: 549: 546: 543: 540: 537: 534: 531: 528: 525: 522: 519: 516: 513: 510: 507: 504: 501: 498: 495: 492: 489: 486: 483: 480: 477: 474: 471: 468: 465: 462: 459: 456: 453: 450: 447: 444: 443:<iostream> 441: 415: 396: 394:reinterpret_cast 265:comparison etc. 226:in mathematics. 218:, a union has a 186: 182: 145:computer science 136: 129: 125: 122: 116: 114: 73: 49: 41: 21: 3517: 3516: 3512: 3511: 3510: 3508: 3507: 3506: 3482: 3481: 3480: 3475: 3456:Type conversion 3391: 3385: 3321:Enumerated type 3294: 3180: 3174:null-terminated 3150: 3115: 3003: 2960: 2955: 2925: 2920: 2907: 2879: 2773: 2769:XOR linked list 2735: 2711:Circular buffer 2692: 2611: 2590: 2588:Data structures 2585: 2530: 2517: 2515: 2513: 2492: 2489: 2479: 2477: 2469: 2468: 2464: 2454: 2452: 2444: 2443: 2439: 2429: 2427: 2425:docs.python.org 2419: 2418: 2414: 2404: 2402: 2393: 2392: 2388: 2379: 2377: 2369: 2368: 2364: 2355: 2353: 2345: 2344: 2340: 2331: 2329: 2321: 2320: 2316: 2307: 2305: 2297: 2296: 2292: 2282: 2280: 2277: 2270: 2269: 2262: 2252: 2250: 2246: 2239: 2238: 2234: 2221: 2220: 2216: 2202: 2201: 2197: 2188: 2186: 2182: 2181: 2177: 2142: 2141: 2137: 2133: 2127: 2125: 2124: 2121: 2118: 2115: 2112: 2109: 2106: 2103: 2100: 2097: 2094: 2091: 2088: 2085: 2082: 2079: 2076: 2073: 2070: 2067: 2064: 2061: 2058: 2054: 2051: 2048: 2045: 2042: 2039: 2031: 2023: 2022: 2019: 2016: 2013: 2009: 2006: 2003: 1999: 1996: 1993: 1990: 1982: 1978: 1977: 1974: 1971: 1968: 1964: 1961: 1958: 1954: 1951: 1948: 1945: 1942: 1939: 1936: 1933: 1930: 1927: 1919: 1915: 1910: 1909: 1906: 1903: 1900: 1897: 1894: 1891: 1888: 1885: 1882: 1879: 1876: 1873: 1870: 1867: 1864: 1861: 1858: 1855: 1852: 1850:// do something 1849: 1846: 1843: 1840: 1837: 1834: 1831: 1828: 1825: 1822: 1819: 1816: 1813: 1810: 1807: 1804: 1801: 1798: 1795: 1792: 1789: 1786: 1783: 1780: 1777: 1774: 1771: 1768: 1765: 1762: 1759: 1756: 1753: 1750: 1747: 1744: 1741: 1738: 1735: 1732: 1729: 1726: 1723: 1720: 1712: 1708: 1705: 1700: 1699: 1696: 1693: 1690: 1687: 1684: 1681: 1678: 1675: 1672: 1669: 1666: 1663: 1660: 1657: 1654: 1651: 1648: 1645: 1642: 1639: 1636: 1633: 1630: 1627: 1624: 1621: 1618: 1615: 1612: 1609: 1603: 1598: 1597: 1594: 1591: 1588: 1585: 1582: 1579: 1576: 1573: 1570: 1567: 1564: 1561: 1558: 1555: 1552: 1549: 1546: 1543: 1540: 1537: 1534: 1531: 1528: 1525: 1522: 1519: 1516: 1513: 1510: 1507: 1504: 1501: 1498: 1495: 1489: 1480: 1476: 1472: 1469: 1468: 1465: 1462: 1459: 1456: 1453: 1450: 1447: 1444: 1441: 1438: 1435: 1432: 1429: 1426: 1423: 1420: 1417: 1414: 1411: 1408: 1405: 1402: 1399: 1396: 1393: 1390: 1387: 1384: 1381: 1378: 1368: 1364: 1360: 1356: 1352: 1349: 1348: 1345: 1342: 1339: 1336: 1333: 1330: 1327: 1324: 1321: 1318: 1315: 1312: 1309: 1306: 1303: 1300: 1297: 1294: 1291: 1288: 1285: 1282: 1279: 1276: 1270: 1269: 1266: 1263: 1260: 1257: 1254: 1251: 1248: 1245: 1242: 1239: 1236: 1233: 1230: 1227: 1224: 1221: 1218: 1215: 1212: 1209: 1206: 1203: 1200: 1197: 1194: 1191: 1188: 1185: 1182: 1179: 1176: 1173: 1170: 1167: 1164: 1161: 1158: 1155: 1152: 1149: 1146: 1143: 1140: 1137: 1131: 1126: 1112: 1106: 1100: 1087: 1080: 1072: 1071: 1068: 1065: 1062: 1059: 1056: 1053: 1050: 1047: 1044: 1041: 1038: 1035: 1021: 1016: 1015: 1012: 1009: 1006: 1003: 1000: 997: 994: 991: 988: 985: 982: 979: 976: 973: 970: 967: 964: 961: 958: 955: 952: 949: 946: 943: 940: 937: 934: 931: 928: 925: 922: 919: 916: 913: 910: 907: 904: 901: 898: 895: 892: 889: 886: 883: 880: 877: 874: 871: 868: 865: 862: 859: 850: 849: 846: 843: 840: 837: 834: 831: 828: 825: 822: 819: 816: 813: 810: 807: 804: 801: 798: 795: 792: 764: 759: 758: 755: 752: 749: 746: 743: 740: 737: 734: 731: 728: 725: 722: 719: 707: 703: 699: 696: 695: 692: 689: 686: 683: 680: 677: 674: 671: 668: 665: 662: 659: 657:PERSON-NAME-MID 656: 653: 650: 647: 644: 641: 638: 635: 632: 629: 626: 623: 620: 617: 614: 611: 604: 600: 596: 592: 585: 572: 563: 560: 559: 556: 553: 550: 547: 544: 541: 538: 535: 532: 529: 526: 523: 520: 517: 514: 511: 508: 505: 502: 499: 496: 493: 490: 487: 484: 481: 478: 475: 472: 469: 466: 463: 460: 457: 454: 451: 449:<cstdint> 448: 445: 442: 439: 422: 420:Anonymous union 416: 413: 392: 355: 347: 276: 271: 243: 241:Untagged unions 184: 180: 137: 126: 120: 117: 74: 72: 62: 50: 39: 28: 23: 22: 15: 12: 11: 5: 3515: 3513: 3505: 3504: 3499: 3494: 3484: 3483: 3477: 3476: 3474: 3473: 3468: 3463: 3458: 3453: 3448: 3443: 3438: 3433: 3428: 3427: 3426: 3416: 3411: 3409:Data structure 3406: 3401: 3395: 3393: 3387: 3386: 3384: 3383: 3378: 3373: 3368: 3363: 3358: 3353: 3348: 3343: 3338: 3333: 3328: 3323: 3318: 3313: 3308: 3302: 3300: 3296: 3295: 3293: 3292: 3291: 3290: 3280: 3275: 3270: 3265: 3260: 3255: 3254: 3253: 3243: 3238: 3233: 3228: 3223: 3218: 3213: 3208: 3203: 3202: 3201: 3190: 3188: 3182: 3181: 3179: 3178: 3177: 3176: 3166: 3160: 3158: 3152: 3151: 3149: 3148: 3143: 3142: 3141: 3136: 3125: 3123: 3117: 3116: 3114: 3113: 3108: 3103: 3102: 3101: 3091: 3090: 3089: 3088: 3087: 3077: 3072: 3067: 3062: 3057: 3056: 3055: 3050: 3048:Half precision 3045: 3035:Floating point 3032: 3027: 3022: 3017: 3011: 3009: 3005: 3004: 3002: 3001: 2996: 2991: 2986: 2981: 2976: 2970: 2968: 2962: 2961: 2956: 2954: 2953: 2946: 2939: 2931: 2922: 2921: 2919: 2918: 2912: 2909: 2908: 2906: 2905: 2900: 2895: 2889: 2887: 2881: 2880: 2878: 2877: 2876: 2875: 2865: 2864: 2863: 2861:Hilbert R-tree 2858: 2853: 2843: 2842: 2841: 2839:Fibonacci heap 2836: 2831: 2821: 2820: 2819: 2814: 2809: 2807:Red–black tree 2804: 2799: 2789: 2783: 2781: 2775: 2774: 2772: 2771: 2766: 2761: 2756: 2751: 2745: 2743: 2737: 2736: 2734: 2733: 2728: 2723: 2718: 2713: 2708: 2702: 2700: 2694: 2693: 2691: 2690: 2689: 2688: 2683: 2673: 2672: 2671: 2664:Priority queue 2661: 2660: 2659: 2649: 2644: 2639: 2638: 2637: 2632: 2621: 2619: 2613: 2612: 2610: 2609: 2604: 2598: 2596: 2592: 2591: 2586: 2584: 2583: 2576: 2569: 2561: 2555: 2554: 2549: 2543: 2537: 2534:boost::variant 2529: 2528:External links 2526: 2525: 2524: 2512:978-0131101630 2511: 2488: 2487: 2462: 2437: 2412: 2386: 2362: 2338: 2314: 2290: 2260: 2232: 2214: 2195: 2175: 2158:(3): 201–208. 2146:(March 1993). 2134: 2132: 2129: 2038: 1989: 1926: 1914: 1911: 1719: 1704: 1701: 1631:square_and_add 1608: 1602: 1599: 1494: 1488: 1485: 1477:*symtab.u.sval 1377: 1275: 1136: 1130: 1127: 1125: 1122: 1079: 1076: 1034: 1020: 1017: 858: 791: 763: 760: 718: 675:PACKED-DECIMAL 610: 584: 581: 571: 568: 438: 421: 418: 411: 354: 351: 284: 275: 272: 270: 267: 242: 239: 224:disjoint union 165:data structure 139: 138: 53: 51: 44: 26: 24: 14: 13: 10: 9: 6: 4: 3: 2: 3514: 3503: 3500: 3498: 3495: 3493: 3490: 3489: 3487: 3472: 3469: 3467: 3464: 3462: 3459: 3457: 3454: 3452: 3449: 3447: 3444: 3442: 3439: 3437: 3434: 3432: 3429: 3425: 3422: 3421: 3420: 3417: 3415: 3412: 3410: 3407: 3405: 3402: 3400: 3397: 3396: 3394: 3388: 3382: 3379: 3377: 3374: 3372: 3369: 3367: 3364: 3362: 3359: 3357: 3354: 3352: 3349: 3347: 3344: 3342: 3339: 3337: 3334: 3332: 3331:Function type 3329: 3327: 3324: 3322: 3319: 3317: 3314: 3312: 3309: 3307: 3304: 3303: 3301: 3297: 3289: 3286: 3285: 3284: 3281: 3279: 3276: 3274: 3271: 3269: 3266: 3264: 3261: 3259: 3256: 3252: 3249: 3248: 3247: 3244: 3242: 3239: 3237: 3234: 3232: 3229: 3227: 3224: 3222: 3219: 3217: 3214: 3212: 3209: 3207: 3204: 3200: 3197: 3196: 3195: 3192: 3191: 3189: 3187: 3183: 3175: 3172: 3171: 3170: 3167: 3165: 3162: 3161: 3159: 3157: 3153: 3147: 3144: 3140: 3137: 3135: 3132: 3131: 3130: 3127: 3126: 3124: 3122: 3118: 3112: 3109: 3107: 3104: 3100: 3097: 3096: 3095: 3092: 3086: 3083: 3082: 3081: 3078: 3076: 3073: 3071: 3068: 3066: 3063: 3061: 3058: 3054: 3051: 3049: 3046: 3044: 3041: 3040: 3038: 3037: 3036: 3033: 3031: 3028: 3026: 3023: 3021: 3018: 3016: 3013: 3012: 3010: 3006: 3000: 2997: 2995: 2992: 2990: 2987: 2985: 2982: 2980: 2977: 2975: 2972: 2971: 2969: 2967: 2966:Uninterpreted 2963: 2959: 2952: 2947: 2945: 2940: 2938: 2933: 2932: 2929: 2917: 2914: 2913: 2910: 2904: 2901: 2899: 2896: 2894: 2891: 2890: 2888: 2886: 2882: 2874: 2871: 2870: 2869: 2866: 2862: 2859: 2857: 2854: 2852: 2849: 2848: 2847: 2844: 2840: 2837: 2835: 2834:Binomial heap 2832: 2830: 2827: 2826: 2825: 2822: 2818: 2815: 2813: 2810: 2808: 2805: 2803: 2800: 2798: 2795: 2794: 2793: 2790: 2788: 2785: 2784: 2782: 2780: 2776: 2770: 2767: 2765: 2762: 2760: 2757: 2755: 2752: 2750: 2747: 2746: 2744: 2742: 2738: 2732: 2731:Sparse matrix 2729: 2727: 2724: 2722: 2719: 2717: 2716:Dynamic array 2714: 2712: 2709: 2707: 2704: 2703: 2701: 2699: 2695: 2687: 2684: 2682: 2679: 2678: 2677: 2674: 2670: 2667: 2666: 2665: 2662: 2658: 2655: 2654: 2653: 2650: 2648: 2645: 2643: 2640: 2636: 2633: 2631: 2628: 2627: 2626: 2623: 2622: 2620: 2618: 2614: 2608: 2605: 2603: 2600: 2599: 2597: 2593: 2589: 2582: 2577: 2575: 2570: 2568: 2563: 2562: 2559: 2553: 2550: 2547: 2544: 2541: 2538: 2535: 2532: 2531: 2527: 2514: 2508: 2504: 2499: 2498: 2491: 2490: 2476: 2472: 2466: 2463: 2451: 2447: 2441: 2438: 2426: 2422: 2416: 2413: 2401: 2397: 2390: 2387: 2376: 2372: 2366: 2363: 2352: 2348: 2342: 2339: 2328: 2324: 2318: 2315: 2304: 2300: 2294: 2291: 2276: 2275: 2267: 2265: 2261: 2245: 2244: 2236: 2233: 2228: 2224: 2218: 2215: 2210: 2206: 2199: 2196: 2185: 2179: 2176: 2172: 2166: 2161: 2157: 2153: 2149: 2145: 2139: 2136: 2130: 2128: 2036: 2028: 1987: 1924: 1912: 1717: 1702: 1606: 1600: 1492: 1486: 1484: 1481:symtab.u.sval 1473:symtab.u.ival 1375: 1372: 1273: 1134: 1128: 1123: 1121: 1119: 1096: 1094: 1084: 1077: 1075: 1032: 1030: 1026: 1018: 856: 853: 789: 786: 784: 780: 776: 771: 769: 761: 716: 713: 608: 590: 582: 580: 569: 567: 436: 433: 431: 427: 419: 410: 408: 402: 400: 395: 389: 387: 383: 378: 376: 372: 368: 364: 360: 352: 350: 346: 342: 338: 334: 330: 326: 322: 318: 314: 310: 306: 302: 298: 294: 290: 287: 283: 280: 273: 268: 266: 262: 259: 255: 250: 248: 240: 238: 236: 232: 227: 225: 221: 217: 212: 210: 206: 202: 196: 194: 190: 178: 174: 170: 166: 162: 158: 154: 150: 146: 135: 132: 124: 113: 110: 106: 103: 99: 96: 92: 89: 85: 82: –  81: 77: 76:Find sources: 70: 66: 60: 59: 54:This article 52: 48: 43: 42: 37: 33: 19: 3282: 3236:Intersection 2686:Disjoint-set 2516:. Retrieved 2496: 2478:. Retrieved 2474: 2465: 2453:. Retrieved 2449: 2440: 2428:. Retrieved 2424: 2415: 2403:. Retrieved 2399: 2389: 2378:. Retrieved 2374: 2365: 2354:. Retrieved 2350: 2341: 2330:. Retrieved 2326: 2317: 2306:. Retrieved 2302: 2293: 2281:. Retrieved 2273: 2251:. Retrieved 2249:. p. 52 2242: 2235: 2226: 2217: 2208: 2198: 2187:. Retrieved 2178: 2169: 2155: 2151: 2138: 2126: 2024: 1979: 1916: 1706: 1604: 1529:squareAndAdd 1490: 1470: 1373: 1350: 1271: 1132: 1097: 1081: 1073: 1028: 1022: 854: 851: 787: 785:is 32 bits. 782: 778: 774: 772: 765: 711: 697: 586: 573: 561: 542:'\n' 434: 423: 404: 390: 386:polymorphism 382:type punning 379: 356: 348: 344: 340: 336: 332: 328: 324: 320: 316: 312: 308: 304: 300: 296: 292: 288: 285: 277: 263: 251: 244: 235:tagged union 228: 213: 197: 192: 172: 148: 142: 127: 118: 108: 101: 94: 87: 80:"Union type" 75: 63:Please help 58:verification 55: 3466:Type theory 3461:Type system 3311:Bottom type 3258:Option type 3199:generalized 3085:Long double 3030:Fixed point 2829:Binary heap 2754:Linked list 2546:differences 2480:30 November 2455:8 September 2430:8 September 2405:30 November 684:PERSON-DATA 624:PERSON-NAME 601:PERSON-DATA 216:type theory 175:for such a 121:August 2009 36:Union (SQL) 3492:Data types 3486:Categories 3371:Empty type 3366:Type class 3316:Collection 3273:Refinement 3251:metaobject 3099:signedness 2958:Data types 2817:Splay tree 2721:Hash table 2602:Collection 2450:Python.org 2380:2023-04-25 2356:2023-04-25 2332:2023-04-25 2308:2023-04-25 2189:2016-12-29 2131:References 1838:instanceof 1713:instanceof 1703:TypeScript 1066:vers_bytes 893:Dimensions 747:VERS-BYTES 708:VERS-BYTES 690:PERSON-REC 615:PERSON-REC 605:PERSON-REC 597:PERSON-REC 231:assignment 173:union type 171:support a 91:newspapers 3446:Subtyping 3441:Interface 3424:metaclass 3376:Unit type 3346:Semaphore 3326:Exception 3231:Inductive 3221:Dependent 3186:Composite 3164:Character 3146:Reference 3043:Minifloat 2999:Bit array 2873:Hash tree 2759:Skip list 2706:Bit array 2607:Container 2400:PHP.Watch 1986:keyword: 1724:successor 1039:vers_info 753:REDEFINES 735:PIC S9(4) 723:VERS-INFO 712:redefined 700:REDEFINES 669:PERSON-ID 648:PIC X(16) 636:PIC X(12) 177:data type 3471:Variable 3361:Top type 3226:Equality 3134:physical 3111:Rational 3106:Interval 3053:bfloat16 2802:AVL tree 2681:Multiset 2630:Multimap 2617:Abstract 1781:function 1721:function 1526:function 1363:) named 1258:variable 1237:variable 1225:datatype 1201:variable 1186:datatype 1171:variable 1156:datatype 1051:vers_num 965:Triangle 926:Diameter 884:Triangle 841:absolute 823:absolute 756:VERS-NUM 750:PIC X(2) 732:VERS-NUM 704:VERS-NUM 672:PIC 9(9) 539:<< 533:<< 521:<< 515:<< 479:uint32_t 446:#include 440:#include 424:In C++, 412:—  279:ALGOL 68 274:ALGOL 68 220:sum type 161:variable 3414:Generic 3390:Related 3306:Boolean 3263:Product 3139:virtual 3129:Address 3121:Pointer 3094:Integer 3025:Decimal 3020:Complex 3008:Numeric 2856:R+ tree 2851:R* tree 2797:AA tree 2518:Jan 23, 2283:Jan 22, 2253:Jan 22, 2035:block: 1613:Example 1505:private 1499:Example 838:Integer 802:Integer 783:integer 687:RENAMES 593:RENAMES 430:methods 367:structs 185:integer 167:. Some 105:scholar 3404:Boxing 3392:topics 3351:Stream 3288:tagged 3246:Object 3169:String 2885:Graphs 2846:R-tree 2787:B-tree 2741:Linked 2698:Arrays 2509:  2104:unsafe 2074:unsafe 2032:unsafe 1959:String 1865:typeof 1817:number 1808:string 1796:string 1766:return 1757:bigint 1751:number 1742:bigint 1736:number 1709:typeof 1676:return 1601:Python 1580:$ this 1565:return 1523:public 1463:symtab 1379:struct 1286:struct 1113:unsafe 1057:binary 992:Angle2 986:Angle1 941:Square 917:Circle 905:Figure 899:record 878:Square 872:Circle 768:Pascal 762:Pascal 564:struct 548:return 407:object 375:string 333:string 305:string 189:record 157:memory 107:  100:  93:  86:  78:  3299:Other 3283:Union 3216:Class 3206:Array 2989:Tryte 2779:Trees 2652:Queue 2647:Stack 2595:Types 2278:(PDF) 2247:(PDF) 1991:union 1983:union 1841:Array 1802:Array 1670:float 1661:-> 1655:float 1610:class 1583:-> 1568:$ bar 1559:float 1544:$ bar 1535:float 1517:$ foo 1514:float 1496:class 1430:float 1415:union 1409:utype 1388:flags 1361:name2 1357:name1 1304:float 1289:name2 1280:name1 1277:union 1255:union 1138:union 1129:C/C++ 1101:union 1054:fixed 1042:union 950:Width 911:Shape 863:Shape 814:array 660:PIC X 589:COBOL 583:COBOL 500:3.14f 470:float 464:union 371:C++11 353:C/C++ 293:union 258:union 205:words 201:bytes 181:float 153:value 151:is a 149:union 112:JSTOR 98:books 3419:Kind 3381:Void 3241:List 3156:Text 2994:Word 2984:Trit 2979:Byte 2868:Trie 2824:Heap 2642:List 2520:2018 2507:ISBN 2482:2020 2457:2021 2432:2021 2407:2020 2285:2018 2255:2018 2014:bool 1928:enum 1920:enum 1913:Rust 1895:else 1856:else 1811:> 1805:< 1691:self 1637:self 1445:sval 1439:char 1433:fval 1424:ival 1400:name 1394:char 1365:svar 1353:uvar 1343:uvar 1325:svar 1313:char 1264:> 1261:name 1252:< 1243:> 1240:name 1231:< 1228:> 1222:< 1207:> 1204:name 1192:< 1189:> 1183:< 1177:> 1174:name 1162:< 1159:> 1153:< 1147:> 1144:name 1141:< 1088:enum 1083:Rust 1078:Rust 1029:cell 1025:PL/I 1019:PL/I 980:real 974:Side 956:real 932:real 902:case 860:type 820:Byte 779:word 775:byte 744:05 738:COMP 729:05 720:01 681:01 666:05 654:10 642:10 630:10 621:05 612:01 512:cout 455:main 361:and 345:esac 337:void 325:real 317:case 313:node 311:); 309:void 297:real 289:node 286:mode 183:and 147:, a 84:news 3278:Set 2974:Bit 2676:Set 2503:138 2160:doi 2116:baz 2095:let 2086:bar 2065:let 2055:bar 2049:Foo 2040:let 2010:baz 2004:i32 2000:bar 1994:Foo 1969:i32 1949:Baz 1943:i32 1937:Bar 1931:Foo 1877:=== 1697:foo 1679:bar 1664:int 1649:int 1643:bar 1628:def 1619:foo 1586:foo 1553:int 1541:int 1508:int 1487:PHP 1479:or 1421:int 1406:int 1385:int 1331:int 1295:int 1234:nth 1036:1 1023:In 1010:end 1004:360 793:var 766:In 587:In 530:hex 524:std 506:std 452:int 426:C11 363:C++ 357:In 341:out 329:int 301:int 254:set 214:In 203:or 193:and 143:In 67:by 34:or 3488:: 2505:. 2473:. 2448:. 2423:. 2398:. 2373:. 2349:. 2325:. 2301:. 2263:^ 2225:. 2207:. 2168:. 2156:28 2154:. 2150:. 2119:}; 2089:}; 2062:}; 2059:10 2057:: 2012:: 2002:: 1972:}, 1967:: 1957:: 1946:), 1859:if 1829:if 1769:++ 1682:** 1571:** 1483:. 1371:. 1198:nd 1168:st 1120:. 1063:5 1048:5 1001:.. 914:of 817:of 527::: 509::: 491:}; 458:() 321:in 319:n 307:, 303:, 299:, 291:= 237:. 2950:e 2943:t 2936:v 2580:e 2573:t 2566:v 2522:. 2484:. 2459:. 2434:. 2409:. 2383:. 2359:. 2335:. 2311:. 2287:. 2257:. 2229:. 2211:. 2192:. 2162:: 2113:. 2110:x 2107:{ 2101:= 2098:z 2083:. 2080:x 2077:{ 2071:= 2068:y 2052:{ 2046:= 2043:x 2020:} 2017:, 2007:, 1997:{ 1975:} 1965:y 1962:, 1955:x 1952:{ 1940:( 1934:{ 1907:} 1904:} 1898:{ 1892:} 1886:{ 1883:) 1874:) 1871:v 1868:( 1862:( 1853:} 1847:{ 1844:) 1835:v 1832:( 1823:{ 1820:) 1814:| 1799:| 1793:: 1790:v 1787:( 1778:} 1775:; 1772:n 1760:{ 1754:| 1748:: 1745:) 1739:| 1733:: 1730:n 1727:( 1694:. 1688:+ 1685:2 1673:: 1667:| 1658:) 1652:| 1646:: 1640:, 1634:( 1625:0 1622:= 1616:: 1595:} 1592:} 1589:; 1577:+ 1574:2 1562:{ 1556:| 1550:: 1547:) 1538:| 1532:( 1520:; 1511:| 1502:{ 1466:; 1460:} 1457:; 1454:u 1451:} 1448:; 1442:* 1436:; 1427:; 1418:{ 1412:; 1403:; 1397:* 1391:; 1382:{ 1369:d 1346:; 1340:} 1337:; 1334:d 1328:; 1322:} 1319:; 1316:c 1310:; 1307:b 1301:; 1298:a 1292:{ 1283:{ 1267:; 1249:} 1246:; 1219:. 1216:. 1213:. 1210:; 1195:2 1180:; 1165:1 1150:{ 1107:# 1060:, 1045:, 1013:; 1007:) 998:0 995:: 989:, 983:; 977:: 971:( 968:: 962:; 959:) 953:: 947:( 944:: 938:; 935:) 929:: 923:( 920:: 908:: 896:= 890:; 887:) 881:, 875:, 869:( 866:= 847:; 844:0 835:: 832:C 829:; 826:A 811:: 808:B 805:; 799:: 796:A 741:. 726:. 693:. 678:. 663:. 651:. 639:. 627:. 618:. 557:} 554:; 551:0 545:; 536:d 503:; 497:= 494:f 485:; 482:d 476:; 473:f 467:{ 461:{ 359:C 323:( 295:( 247:C 134:) 128:( 123:) 119:( 109:· 102:· 95:· 88:· 61:. 38:. 20:)

Index

Union (computer science)
Union (set theory)
Union (SQL)

verification
improve this article
adding citations to reliable sources
"Union type"
news
newspapers
books
scholar
JSTOR
Learn how and when to remove this message
computer science
value
memory
variable
data structure
programming languages
data type
record
bytes
words
abstract data types
type theory
sum type
disjoint union
assignment
tagged union

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.