Knowledge (XXG)

Type punning

Source 📝

63: 22: 165: 710:
This kind of type punning is more dangerous than most. Whereas the former example relied only on guarantees made by the C programming language about structure layout and pointer convertibility, the latter example relies on assumptions about a particular system's hardware. Some situations, such as
1700:
Where "new" is the standard routine in Pascal for allocating memory for a pointer, and "hex" is presumably a routine to print the hexadecimal string describing the value of an integer. This would allow the display of the address of a pointer, something which is not normally permitted. (Pointers
1499:
In Pascal, copying a real to an integer converts it to the truncated value. This method would translate the binary value of the floating-point number into whatever it is as a long integer (32 bit), which will not be the same and may be incompatible with the long integer value on some systems.
1503:
These examples could be used to create strange conversions, although, in some cases, there may be legitimate uses for these types of constructs, such as for determining locations of particular pieces of data. In the following example a pointer and a longint are both presumed to be 32 bit:
2595:
If the member used to read the contents of a union object is not the same as the member last used to store a value in the object, the appropriate part of the object representation of the value is reinterpreted as an object representation in the new type as described in 6.2.6
526:
Often seen in the programming world is the use of "padded" data structures to allow for the storage of different kinds of values in what is effectively the same storage space. This is often seen when two structures are used in mutual exclusivity for optimization.
780:, causing problems that are unchecked by the compiler. Even when data size and pointer representation match, however, compilers can rely on the non-aliasing constraints to perform optimizations that would be unsafe in the presence of disallowed aliasing. 1792:
The reinterpret cast technique from C/C++ also works in Pascal. This can be useful, when eg. reading dwords from a byte stream, and we want to treat them as float. Here is a working example, where we reinterpret-cast a dword to a float:
759:
In addition to the assumption about bit-representation of floating-point numbers, the above floating-point type-punning example also violates the C language's constraints on how objects are accessed: the declared type of
1789:
This construct may cause a program check or protection violation if address 0 is protected against reading on the machine the program is running upon or the operating system it is running under.
1701:
cannot be read or written, only assigned.) Assigning a value to an integer variant of a pointer would allow examining or writing to any location in system memory:
1878:(and other .NET languages), type punning is a little harder to achieve because of the type system, but can be done nonetheless, using pointers or struct unions. 2053:
can be used instead of C#, because it doesn't have most of the type limitations. This allows one to, for example, combine two enum values of a generic type:
2615: 2576: 2527: 875:
The C standard's aliasing rules state that an object shall have its stored value accessed only by an lvalue expression of a compatible type. The types
520: 268:
to this list — are provided in order to permit many kinds of type punning, although some kinds are not actually supported by the standard language.
1195:
A variant record permits treating a data type as multiple kinds of data depending on which variant is being referenced. In the following example,
887:. Although on GCC and LLVM this particular program compiles and runs as expected, more complicated examples may interact with assumptions made by 1021:, is an allowed form of type-punning in C, provided that the member read is not larger than the one whose value was set (otherwise the read has 788:
A naive attempt at type-punning can be achieved by using pointers: (The following running example assumes IEEE-754 bit-representation for type
175: 1890:), enum, array or struct that is composed only of other native types. Note that pointers are only allowed in code blocks marked 'unsafe'. 207: 146: 49: 895:
will ensure correct behavior of code using this form of type-punning, although using other forms of type punning is recommended.
2705: 516: 1875: 720: 491:; and, in addition, that the two structure types share the same memory layout. Therefore, a reference to the structure field 248: 84: 2661: 127: 272: 80: 35: 535:
Not all examples of type punning involve structures, as the previous example did. Suppose we want to determine whether a
236:
in order to achieve an effect that would be difficult or impossible to achieve within the bounds of the formal language.
99: 2050: 590: 261: 106: 73: 2546:
An object shall have its stored value accessed only by an lvalue expression that has one of the following types:
1950:
Struct unions are allowed without any notion of 'unsafe' code, but they do require the definition of a new type.
276: 2626: 2587: 2538: 773: 735: 480: 256: 240: 113: 742:, fast FP comparison as integers, and finding neighboring values by incrementing as an integer (implementing 2665: 283:
may be used to treat a particular data type in more than one manner, or in a manner not normally permitted.
95: 724: 716: 772:. On many common platforms, this use of pointer punning can create problems if different pointers are 2500: 2686:, and discussing the issues surrounding the implementation-defined behavior of the last example above 1022: 777: 233: 2236:// this will not cause an overflow, because a and b have the same type, and therefore the same size. 712: 1037: 1026: 884: 1059:
function allows type punning with no undefined behavior. It also allows the function be labeled
41: 2689: 2675: 1269:(* not show here: there can be several variables in a variant record's case statement *) 515:). In other words, the sockets library uses type punning to implement a rudimentary form of 292: 221: 888: 728: 585:
However, supposing that floating-point comparisons are expensive, and also supposing that
251: 120: 851:// In C++ this is equivalent to: int32_t i = *reinterpret_cast<int32_t*>(&x); 536: 2634:
The following are unspecified: … The values of bytes that correspond to union members
2251:
CIL opcode allows for some other tricks, such as converting a struct to a byte array:
2699: 1886:
C# only allows pointers to so-called native types, i.e. any primitive type (except
280: 719:, may require dangerous code. In these cases, documenting all such assumptions in 684: 593:, and integers are 32 bits wide, we could engage in type punning to extract the 229: 62: 2436:// this is the *address* of 'v', because its type is '!!T&' 296: 906:
In C, but not in C++, it is sometimes possible to perform type punning via a
679:
Note that the behaviour will not be exactly the same: in the special case of
739: 594: 295:
interface. The function to bind an opened but uninitialized socket to an
2367:// create a new byte array with length sizeof(T) and store it in local 0 1052: 2558: 479:
The Berkeley sockets library fundamentally relies on the fact that in
2482: 244: 1207:
are presumed to be 32, while character is presumed to be 8 bit:
2679: 700: 228:
is any programming technique that subverts or circumvents the
158: 56: 15: 597:
of the floating-point number using only integer operations:
2682:
standard, incidentally defining "type punning" in terms of
727:
to verify portability expectations, helps to keep the code
1029:
in C++, however, where only the last-written member of a
182: 883:
are not compatible, therefore this code's behavior is
734:
Practical examples of floating-point punning include
2108:
This can be circumvented by the following CIL code:
291:
One classic example of type punning is found in the
2424:// <the array is still on the stack, see (1)> 743: 87:. Unsourced material may be challenged and removed. 1017:after most recently writing to the other member, 776:. Furthermore, pointers of different sizes can 1455:(* this would extract the first byte of V.I *) 1494:(* this would store a Real into an Integer *) 768:but it is read through an expression of type 695:. Also, the first implementation will return 8: 1671:'Variable PP is located at address ' 1025:). The same is syntactically valid but has 50:Learn how and when to remove these messages 1772:'Word 0 of this machine contains ' 891:and lead to unwanted behavior. The option 715:code that the compiler otherwise fails to 2598:a process sometimes called "type punning" 2388:// keep a copy on the stack for later (1) 1036:For another example of type punning, see 208:Learn how and when to remove this message 147:Learn how and when to remove this message 2505:Random ASCII - tech blog of Bruce Dawson 1033:is considered to have any value at all. 2473: 352:function is usually called as follows: 2421:// memcpy(local 0, &v, sizeof(T)); 707:for NaN values with the sign bit set. 487:is freely convertible to a pointer to 2692:on the use of unions for type punning 7: 2602:This might be a trap representation. 1763:(* K contains the value of word 0 *) 1742:(* PP now points to address 0 *) 539:number is negative. We could write: 85:adding citations to reliable sources 2636:other than the one last stored into 2625:, 2018, p. 403, archived from 703:value, but the latter might return 503:) will actually refer to the field 2586:, 2018, p. 59, archived from 2537:, 2018, p. 55, archived from 687:, the first implementation yields 14: 2672:, which defeats some type punning 778:alias accesses to the same memory 275:programming language, the use of 185:and remove advice or instruction. 31:This article has multiple issues. 1199:is presumed to be 16 bit, while 774:aligned in machine-specific ways 589:is represented according to the 163: 61: 20: 2481:Herf, Michael (December 2001). 72:needs additional citations for 39:or discuss these issues on the 2649:ISO/IEC 14882:2011 Section 9.5 1: 1125:// (enable only on IEEE 754) 591:IEEE floating-point standard 2722: 2577:"§ 6.5.2.3/3, footnote 97" 2487:stereopsis : graphics 2559:"GCC Bugs - GNU Project" 2517:ISO/IEC 9899:1999 s6.5/7 2325:// 'ref T' in C# 2253: 2110: 2055: 1952: 1892: 1795: 1703: 1506: 1209: 1065: 912: 794: 736:fast inverse square root 691:while the second yields 599: 541: 354: 301: 299:is declared as follows: 2706:Programming constructs 531:Floating-point example 493:my_addr->sin_family 2501:"Stupid Float Tricks" 247:, constructs such as 2616:"§ J.1/1, bullet 11" 1023:unspecified behavior 893:-fno-strict-aliasing 264:type conversion and 234:programming language 183:rewrite this article 81:improve this article 2507:. 24 January 2012. 1038:Stride of an array 1027:undefined behavior 723:, and introducing 513:struct sockaddr_in 485:struct sockaddr_in 2690:Defect Report 283 2676:Defect Report 257 2670:-fstrict-aliasing 2623:ISO/IEC 9899:2018 2584:ISO/IEC 9899:2018 2535:ISO/IEC 9899:2018 1994:FloatAndUIntUnion 1958:FloatAndUIntUnion 725:static assertions 218: 217: 210: 200: 199: 176:a manual or guide 157: 156: 149: 131: 54: 2713: 2685: 2671: 2650: 2647: 2641: 2640: 2631: 2620: 2612: 2606: 2605: 2592: 2581: 2573: 2567: 2566: 2555: 2549: 2548: 2543: 2532: 2524: 2518: 2515: 2509: 2508: 2497: 2491: 2490: 2478: 2464: 2461: 2458: 2455: 2452: 2449: 2446: 2443: 2440: 2437: 2434: 2431: 2428: 2425: 2422: 2419: 2416: 2413: 2410: 2407: 2404: 2401: 2398: 2395: 2392: 2389: 2386: 2383: 2380: 2377: 2374: 2371: 2368: 2365: 2362: 2359: 2356: 2353: 2350: 2347: 2344: 2341: 2338: 2335: 2332: 2329: 2326: 2323: 2320: 2317: 2314: 2311: 2308: 2305: 2302: 2299: 2296: 2293: 2290: 2287: 2284: 2281: 2278: 2275: 2272: 2269: 2266: 2263: 2260: 2257: 2250: 2243: 2240: 2237: 2234: 2231: 2228: 2225: 2222: 2219: 2216: 2213: 2210: 2207: 2204: 2201: 2198: 2195: 2192: 2189: 2186: 2183: 2180: 2177: 2174: 2171: 2168: 2165: 2162: 2159: 2156: 2153: 2150: 2147: 2144: 2141: 2138: 2135: 2132: 2129: 2126: 2123: 2120: 2117: 2114: 2104: 2101: 2098: 2095: 2092: 2089: 2086: 2083: 2080: 2077: 2074: 2071: 2068: 2065: 2062: 2059: 2040: 2037: 2034: 2031: 2028: 2025: 2022: 2019: 2016: 2013: 2010: 2007: 2004: 2001: 1998: 1995: 1992: 1989: 1986: 1983: 1980: 1977: 1974: 1971: 1968: 1965: 1962: 1959: 1956: 1941: 1938: 1935: 1932: 1929: 1926: 1923: 1920: 1917: 1914: 1911: 1908: 1905: 1902: 1899: 1896: 1889: 1865: 1862: 1859: 1856: 1853: 1850: 1847: 1844: 1841: 1838: 1835: 1832: 1829: 1826: 1823: 1820: 1817: 1814: 1811: 1808: 1805: 1802: 1799: 1785: 1782: 1779: 1776: 1773: 1770: 1767: 1764: 1761: 1758: 1755: 1752: 1749: 1746: 1743: 1740: 1737: 1734: 1731: 1728: 1725: 1722: 1719: 1716: 1713: 1710: 1707: 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: 1606: 1603: 1600: 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: 1495: 1492: 1489: 1486: 1483: 1480: 1477: 1474: 1471: 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: 1375: 1372: 1369: 1366: 1363: 1360: 1357: 1354: 1351: 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: 1273: 1270: 1267: 1264: 1261: 1258: 1255: 1252: 1249: 1246: 1243: 1240: 1237: 1234: 1231: 1228: 1225: 1222: 1219: 1216: 1213: 1186: 1183: 1180: 1177: 1174: 1171: 1168: 1165: 1162: 1159: 1156: 1153: 1150: 1147: 1144: 1141: 1138: 1135: 1132: 1129: 1126: 1123: 1120: 1117: 1114: 1111: 1108: 1105: 1102: 1099: 1096: 1093: 1090: 1087: 1084: 1081: 1078: 1075: 1072: 1069: 1062: 1058: 1047: 1032: 1020: 1016: 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: 909: 902: 894: 882: 878: 870: 867: 864: 861: 858: 855: 852: 849: 846: 843: 840: 837: 834: 831: 828: 825: 822: 819: 816: 813: 810: 807: 804: 801: 798: 791: 771: 767: 763: 745: 706: 698: 694: 690: 682: 675: 672: 669: 666: 663: 660: 657: 654: 651: 648: 645: 642: 639: 636: 633: 630: 627: 624: 621: 618: 615: 612: 609: 606: 603: 588: 581: 578: 575: 572: 569: 566: 563: 560: 557: 554: 551: 548: 545: 514: 510: 506: 502: 501:struct sockaddr* 498: 494: 490: 486: 475: 472: 469: 466: 463: 460: 457: 454: 451: 448: 445: 442: 439: 436: 433: 430: 427: 424: 421: 418: 415: 412: 409: 406: 403: 400: 397: 394: 391: 388: 385: 382: 379: 376: 373: 370: 367: 364: 361: 358: 351: 344: 341: 338: 335: 332: 329: 326: 323: 320: 317: 314: 311: 308: 305: 293:Berkeley sockets 267: 266:reinterpret_cast 259: 222:computer science 213: 206: 195: 192: 186: 174:is written like 167: 166: 159: 152: 145: 141: 138: 132: 130: 89: 65: 57: 46: 24: 23: 16: 2721: 2720: 2716: 2715: 2714: 2712: 2711: 2710: 2696: 2695: 2683: 2669: 2658: 2653: 2648: 2644: 2632:on 2018-12-30, 2629: 2618: 2614: 2613: 2609: 2593:on 2018-12-30, 2590: 2579: 2575: 2574: 2570: 2557: 2556: 2552: 2544:on 2018-12-30, 2541: 2530: 2526: 2525: 2521: 2516: 2512: 2499: 2498: 2494: 2480: 2479: 2475: 2471: 2466: 2465: 2462: 2459: 2456: 2453: 2450: 2447: 2444: 2441: 2438: 2435: 2432: 2429: 2426: 2423: 2420: 2417: 2414: 2411: 2408: 2405: 2402: 2399: 2396: 2393: 2390: 2387: 2384: 2381: 2378: 2375: 2372: 2369: 2366: 2363: 2360: 2357: 2354: 2351: 2348: 2345: 2342: 2339: 2336: 2333: 2330: 2327: 2324: 2321: 2318: 2315: 2312: 2309: 2306: 2303: 2300: 2297: 2294: 2291: 2288: 2285: 2282: 2279: 2276: 2273: 2270: 2267: 2264: 2261: 2258: 2255: 2248: 2245: 2244: 2241: 2238: 2235: 2232: 2229: 2226: 2223: 2220: 2217: 2214: 2211: 2208: 2205: 2202: 2199: 2196: 2193: 2190: 2187: 2184: 2181: 2178: 2175: 2172: 2169: 2166: 2163: 2160: 2157: 2154: 2151: 2148: 2145: 2142: 2139: 2136: 2133: 2130: 2127: 2124: 2121: 2118: 2115: 2112: 2106: 2105: 2102: 2099: 2096: 2093: 2090: 2087: 2084: 2081: 2078: 2075: 2072: 2069: 2066: 2063: 2060: 2057: 2047: 2042: 2041: 2038: 2035: 2032: 2029: 2026: 2023: 2020: 2017: 2014: 2011: 2008: 2005: 2002: 1999: 1996: 1993: 1990: 1987: 1984: 1981: 1978: 1975: 1972: 1969: 1966: 1963: 1960: 1957: 1954: 1948: 1943: 1942: 1939: 1936: 1933: 1930: 1927: 1924: 1921: 1918: 1915: 1912: 1909: 1906: 1903: 1900: 1897: 1894: 1887: 1884: 1872: 1867: 1866: 1863: 1860: 1857: 1854: 1851: 1848: 1845: 1842: 1839: 1836: 1833: 1830: 1827: 1824: 1821: 1818: 1815: 1812: 1809: 1806: 1803: 1800: 1797: 1787: 1786: 1783: 1780: 1777: 1774: 1771: 1768: 1765: 1762: 1759: 1756: 1753: 1750: 1747: 1744: 1741: 1738: 1735: 1732: 1729: 1726: 1723: 1720: 1717: 1714: 1711: 1708: 1705: 1698: 1697: 1694: 1691: 1688: 1685: 1682: 1679: 1676: 1673: 1670: 1667: 1664: 1661: 1658: 1655: 1652: 1649: 1646: 1643: 1640: 1637: 1634: 1631: 1628: 1625: 1622: 1619: 1616: 1613: 1610: 1607: 1604: 1601: 1598: 1595: 1592: 1589: 1586: 1583: 1580: 1577: 1574: 1571: 1568: 1565: 1562: 1559: 1556: 1553: 1550: 1547: 1544: 1541: 1538: 1535: 1532: 1529: 1526: 1523: 1520: 1517: 1514: 1511: 1508: 1497: 1496: 1493: 1490: 1487: 1484: 1481: 1478: 1475: 1472: 1469: 1466: 1463: 1460: 1457: 1454: 1451: 1448: 1445: 1442: 1439: 1436: 1433: 1430: 1427: 1424: 1421: 1418: 1415: 1412: 1409: 1406: 1403: 1400: 1397: 1394: 1391: 1388: 1385: 1382: 1379: 1376: 1373: 1370: 1367: 1364: 1361: 1358: 1355: 1352: 1349: 1346: 1343: 1340: 1337: 1334: 1331: 1328: 1325: 1322: 1319: 1316: 1313: 1310: 1307: 1304: 1301: 1298: 1295: 1292: 1289: 1286: 1283: 1280: 1277: 1274: 1271: 1268: 1265: 1262: 1259: 1256: 1253: 1250: 1247: 1244: 1241: 1238: 1235: 1232: 1229: 1226: 1223: 1220: 1217: 1214: 1211: 1193: 1188: 1187: 1184: 1181: 1178: 1175: 1172: 1169: 1166: 1163: 1160: 1157: 1154: 1151: 1148: 1145: 1142: 1139: 1136: 1133: 1130: 1127: 1124: 1121: 1118: 1115: 1112: 1109: 1106: 1103: 1100: 1097: 1094: 1091: 1088: 1085: 1082: 1079: 1076: 1073: 1070: 1067: 1060: 1056: 1049: 1045: 1030: 1018: 1014: 1011: 1010: 1007: 1004: 1001: 998: 995: 992: 989: 986: 983: 980: 977: 974: 971: 968: 965: 962: 959: 956: 953: 950: 947: 944: 941: 938: 935: 932: 929: 926: 923: 920: 917: 914: 907: 904: 900: 892: 889:strict aliasing 880: 876: 874: 872: 871: 868: 865: 862: 859: 856: 853: 850: 847: 844: 841: 838: 835: 832: 829: 826: 823: 820: 817: 814: 811: 808: 805: 802: 799: 796: 789: 786: 784:Use of pointers 769: 765: 761: 757: 752: 738:popularized by 704: 696: 692: 688: 680: 677: 676: 673: 670: 667: 664: 661: 658: 655: 652: 649: 646: 643: 640: 637: 634: 631: 628: 625: 622: 619: 616: 613: 610: 607: 604: 601: 586: 583: 582: 579: 576: 573: 570: 567: 564: 561: 558: 555: 552: 549: 546: 543: 533: 512: 508: 504: 500: 496: 492: 489:struct sockaddr 488: 484: 483:, a pointer to 477: 476: 473: 470: 467: 464: 461: 458: 455: 452: 449: 446: 443: 440: 437: 434: 431: 428: 425: 422: 419: 416: 413: 410: 407: 404: 401: 398: 395: 392: 389: 386: 383: 380: 377: 374: 371: 368: 365: 362: 359: 356: 349: 346: 345: 342: 339: 336: 333: 330: 327: 324: 321: 318: 315: 312: 309: 306: 303: 289: 287:Sockets example 265: 255: 252:type conversion 214: 203: 202: 201: 196: 190: 187: 180: 168: 164: 153: 142: 136: 133: 90: 88: 78: 66: 25: 21: 12: 11: 5: 2719: 2717: 2709: 2708: 2698: 2697: 2694: 2693: 2687: 2673: 2657: 2656:External links 2654: 2652: 2651: 2642: 2607: 2568: 2550: 2519: 2510: 2492: 2483:"radix tricks" 2472: 2470: 2467: 2254: 2111: 2056: 2046: 2043: 1953: 1947: 1944: 1893: 1883: 1880: 1871: 1868: 1796: 1704: 1507: 1210: 1192: 1189: 1107:numeric_limits 1066: 1048: 1042: 913: 903: 897: 795: 785: 782: 756: 753: 751: 748: 600: 542: 537:floating-point 532: 529: 355: 302: 288: 285: 216: 215: 198: 197: 171: 169: 162: 155: 154: 96:"Type punning" 69: 67: 60: 55: 29: 28: 26: 19: 13: 10: 9: 6: 4: 3: 2: 2718: 2707: 2704: 2703: 2701: 2691: 2688: 2681: 2677: 2674: 2667: 2663: 2660: 2659: 2655: 2646: 2643: 2639: 2637: 2628: 2624: 2617: 2611: 2608: 2604: 2603: 2599: 2589: 2585: 2578: 2572: 2569: 2564: 2560: 2554: 2551: 2547: 2540: 2536: 2529: 2523: 2520: 2514: 2511: 2506: 2502: 2496: 2493: 2488: 2484: 2477: 2474: 2468: 2252: 2109: 2054: 2052: 2044: 1951: 1946:Struct unions 1945: 1891: 1881: 1879: 1877: 1869: 1794: 1790: 1702: 1505: 1501: 1365:VariantRecord 1215:VariantRecord 1208: 1206: 1202: 1198: 1190: 1095:static_assert 1064: 1057:std::bit_cast 1054: 1043: 1041: 1039: 1034: 1028: 1024: 911: 898: 896: 890: 886: 793: 783: 781: 779: 775: 754: 749: 747: 741: 737: 732: 730: 726: 722: 718: 714: 713:time-critical 708: 702: 686: 685:negative zero 598: 596: 592: 540: 538: 530: 528: 524: 522: 518: 505:sa.sin_family 482: 353: 300: 298: 294: 286: 284: 282: 278: 274: 269: 263: 258: 253: 250: 246: 242: 237: 235: 231: 227: 223: 212: 209: 194: 184: 179: 177: 172:This article 170: 161: 160: 151: 148: 140: 129: 126: 122: 119: 115: 112: 108: 105: 101: 98: –  97: 93: 92:Find sources: 86: 82: 76: 75: 70:This article 68: 64: 59: 58: 53: 51: 44: 43: 38: 37: 32: 27: 18: 17: 2645: 2635: 2633: 2627:the original 2622: 2610: 2601: 2597: 2594: 2588:the original 2583: 2571: 2562: 2553: 2545: 2539:the original 2534: 2522: 2513: 2504: 2495: 2486: 2476: 2246: 2134:CombineEnums 2107: 2048: 2045:Raw CIL code 1949: 1885: 1873: 1791: 1788: 1699: 1502: 1498: 1204: 1200: 1196: 1194: 1050: 1035: 1012: 905: 873: 787: 770:unsigned int 758: 733: 729:maintainable 709: 678: 584: 534: 525: 517:polymorphism 478: 347: 290: 270: 238: 226:type punning 225: 219: 204: 191:October 2011 188: 181:Please help 173: 143: 137:October 2011 134: 124: 117: 110: 103: 91: 79:Please help 74:verification 71: 47: 40: 34: 33:Please help 30: 2563:gcc.gnu.org 2274:ToByteArray 2024:piAsRawData 2009:DataAsFloat 1970:DataAsFloat 1913:piAsRawData 1074:is_negative 918:is_negative 800:is_negative 750:By language 605:is_negative 547:is_negative 521:inheritance 511:is of type 499:is of type 360:sockaddr_in 260:— C++ adds 230:type system 2668:manual on 2638:(6.2.6.1). 2469:References 2103:// illegal 2036:DataAsUInt 1982:DataAsUInt 1019:my_union.d 1015:my_union.i 1013:Accessing 396:sin_family 297:IP address 107:newspapers 36:improve it 2528:"§ 6.5/7" 2298:ValueType 2280:valuetype 2268:hidebysig 2158:ValueType 2140:valuetype 2125:hidebysig 1413:Character 1119:is_iec559 1068:constexpr 1061:constexpr 885:undefined 755:C and C++ 744:nextafter 740:Quake III 337:socklen_t 262:reference 42:talk page 2700:Category 2361:maxstack 2209:maxstack 2085:combined 1882:Pointers 1143:bit_cast 1089:noexcept 1046:bit_cast 990:my_union 969:my_union 963:my_union 721:comments 717:optimize 699:for any 595:sign bit 450:sockaddr 414:sin_port 325:sockaddr 281:variants 2678:to the 2664:of the 2662:Section 2415:ldelema 2334:managed 2200:managed 2015:3.14159 1904:3.14159 1766:WriteLn 1665:WriteLn 1626:LongInt 1590:LongInt 1545:LongInt 1389:LongInt 1377:Integer 1287:LongInt 1260:Integer 1233:LongInt 1227:RecType 1201:longint 1197:integer 1155:int32_t 1044:Use of 899:Use of 881:int32_t 833:int32_t 818:int32_t 507:(where 497:my_addr 495:(where 402:AF_INET 340:addrlen 331:my_addr 277:records 271:In the 249:pointer 121:scholar 2439:sizeof 2379:newarr 2370:sizeof 2343:locals 2292:System 2265:static 2262:public 2259:method 2152:System 2122:static 2119:public 2116:method 1991:// ... 1976:public 1964:public 1955:struct 1888:string 1533:record 1221:record 1191:Pascal 1170:return 1116:>:: 1055:, the 987:return 854:return 683:being 656:return 565:return 468:sizeof 447:struct 438:sockfd 381:sockfd 357:struct 322:struct 316:sockfd 273:Pascal 123:  116:  109:  102:  94:  2684:union 2630:(PDF) 2619:(PDF) 2591:(PDF) 2580:(PDF) 2542:(PDF) 2531:(PDF) 2451:ldloc 2448:cpblk 2427:ldarg 2418:uint8 2391:stloc 2382:uint8 2352:uint8 2319:& 2271:uint8 2249:cpblk 2224:ldarg 2215:ldarg 2188:TEnum 2176:TEnum 2164:TEnum 2131:TEnum 2082:TEnum 2070:TEnum 2058:TEnum 2030:union 2003:union 1997:union 1967:float 1934:& 1895:float 1849:pReal 1825:DWord 1801:pReal 1335:array 1254:array 1113:float 1080:float 1053:C++20 1031:union 951:float 936:union 924:float 908:union 901:union 877:float 842:& 806:float 790:float 766:float 697:false 689:false 647:& 611:float 587:float 553:float 459:& 420:htons 279:with 257:union 232:of a 128:JSTOR 114:books 2346:init 2307:> 2286:ctor 2277:< 2247:The 2167:> 2146:ctor 2137:< 2079:...; 2067:...; 2049:Raw 2021:uint 1979:uint 1925:uint 1910:uint 1837:Real 1810:Real 1798:type 1536:case 1527:Arec 1521:Arec 1509:type 1401:Real 1341:Char 1311:Real 1224:case 1212:type 1205:real 1203:and 1176:< 1158:> 1146:< 1128:auto 1110:< 1071:bool 999:< 915:bool 879:and 860:< 797:bool 705:true 693:true 665:< 602:bool 574:0.0f 571:< 544:bool 432:bind 426:port 387:...; 350:bind 348:The 307:bind 254:and 243:and 224:, a 100:news 2680:C99 2666:GCC 2600:). 2460:ret 2400:ldc 2385:dup 2331:cil 2239:ret 2197:cil 2051:CIL 1874:In 1816:var 1677:Hex 1632:New 1605:var 1599:end 1470:8.3 1356:var 1350:end 1149:std 1137:std 1101:std 1051:In 942:int 792:.) 764:is 746:). 701:NaN 638:int 623:int 519:or 378:int 313:int 304:int 245:C++ 239:In 220:In 83:by 2702:: 2621:, 2582:, 2561:. 2533:, 2503:. 2485:. 2442:!! 2406:i4 2373:!! 2313:!! 2233:or 2185:!! 2173:!! 2128:!! 1937:pi 1898:pi 1876:C# 1870:C# 1864:^; 1858:DW 1846::= 1819:DW 1754:^. 1751:PP 1748::= 1733:^. 1730:PP 1727::= 1724:PP 1715::= 1709:^. 1706:PP 1692:)) 1686:^. 1683:PP 1659:PP 1656::= 1650:^. 1647:PP 1638:PP 1614:PA 1608:PP 1566:PA 1548:of 1539:RT 1512:PA 1479::= 1476:LA 1467::= 1440::= 1437:Ch 1428::= 1407:Ch 1395:RA 1383:LA 1338:of 1257:of 1236:of 1167:); 1152::: 1140::: 1122:); 1104::: 1063:. 1040:. 910:. 731:. 523:. 509:sa 474:); 471:sa 462:sa 429:); 408:sa 390:sa 375:}; 363:sa 343:); 45:. 2596:( 2565:. 2489:. 2463:} 2457:0 2454:. 2445:T 2433:0 2430:. 2412:0 2409:. 2403:. 2397:0 2394:. 2376:T 2364:3 2358:. 2355:) 2349:( 2340:. 2337:{ 2328:) 2322:v 2316:T 2310:( 2304:T 2301:) 2295:. 2289:( 2283:. 2256:. 2242:} 2230:1 2227:. 2221:0 2218:. 2212:2 2206:. 2203:{ 2194:) 2191:b 2182:, 2179:a 2170:( 2161:) 2155:. 2149:( 2143:. 2113:. 2100:; 2097:b 2094:| 2091:a 2088:= 2076:= 2073:b 2064:= 2061:a 2039:; 2033:. 2027:= 2018:; 2012:= 2006:. 2000:; 1988:} 1985:; 1973:; 1961:{ 1940:; 1931:) 1928:* 1922:( 1919:* 1916:= 1907:; 1901:= 1861:) 1855:@ 1852:( 1843:F 1840:; 1834:: 1831:F 1828:; 1822:: 1813:; 1807:^ 1804:= 1784:; 1781:) 1778:K 1775:, 1769:( 1760:; 1757:L 1745:K 1739:; 1736:P 1721:; 1718:0 1712:L 1695:; 1689:L 1680:( 1674:, 1668:( 1662:; 1653:P 1644:; 1641:) 1635:( 1629:; 1623:: 1620:K 1617:; 1611:: 1602:; 1596:; 1593:) 1587:: 1584:L 1581:( 1578:: 1575:2 1572:; 1569:) 1563:: 1560:P 1557:( 1554:: 1551:1 1542:: 1530:= 1524:; 1518:^ 1515:= 1491:; 1488:L 1485:. 1482:V 1473:; 1464:R 1461:. 1458:V 1452:; 1449:C 1446:. 1443:V 1434:; 1431:1 1425:I 1422:. 1419:V 1416:; 1410:: 1404:; 1398:: 1392:; 1386:: 1380:; 1374:: 1371:K 1368:; 1362:: 1359:V 1353:; 1347:; 1344:) 1332:: 1329:C 1326:( 1323:: 1320:4 1317:; 1314:) 1308:: 1305:R 1302:( 1299:: 1296:3 1293:; 1290:) 1284:: 1281:L 1278:( 1275:: 1272:2 1266:; 1263:) 1251:: 1248:I 1245:( 1242:: 1239:1 1230:: 1218:= 1185:} 1182:; 1179:0 1173:i 1164:x 1161:( 1134:= 1131:i 1098:( 1092:{ 1086:) 1083:x 1077:( 1008:} 1005:; 1002:0 996:i 993:. 984:; 981:x 978:= 975:d 972:. 966:; 960:} 957:; 954:d 948:; 945:i 939:{ 933:{ 930:) 927:x 921:( 869:} 866:; 863:0 857:i 848:; 845:x 839:) 836:* 830:( 827:* 824:= 821:i 815:{ 812:) 809:x 803:( 762:x 681:x 674:} 671:; 668:0 662:i 659:* 653:; 650:x 644:) 641:* 635:( 632:= 629:i 626:* 620:{ 617:) 614:x 608:( 580:} 577:; 568:x 562:{ 559:) 556:x 550:( 481:C 465:, 456:) 453:* 444:( 441:, 435:( 423:( 417:= 411:. 405:; 399:= 393:. 384:= 372:0 369:{ 366:= 334:, 328:* 319:, 310:( 241:C 211:) 205:( 193:) 189:( 178:. 150:) 144:( 139:) 135:( 125:· 118:· 111:· 104:· 77:. 52:) 48:(

Index

improve it
talk page
Learn how and when to remove these messages

verification
improve this article
adding citations to reliable sources
"Type punning"
news
newspapers
books
scholar
JSTOR
Learn how and when to remove this message
a manual or guide
rewrite this article
Learn how and when to remove this message
computer science
type system
programming language
C
C++
pointer
type conversion
union
reference
Pascal
records
variants
Berkeley sockets

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