Knowledge (XXG)

Function pointer

Source 📝

1428:
This is how C++ uses function pointers when dealing with member functions of classes or structs. These are invoked using an object pointer or a this call. They are type safe in that you can only call members of that class (or derivatives) using a pointer of that type. This example also
1046:
pointer) which is the pointer to the object it is operating on, so the type of the object must be included as part of the type of the function pointer. The method is then used on an object of that class by using one of the "pointer-to-member" operators:
1023:
may not be able to figure out where to branch to (it depends on the value of the function pointer at run time) although this effect can be overstated as it is often amply compensated for by significantly reduced non-indexed table lookups.
970:, allowing the object to be used within expressions using the same syntax as a function call. Functors are more powerful than simple function pointers, being able to contain their own data values, and allowing the programmer to emulate 1429:
demonstrates the use of a typedef for the pointer to member function added for simplicity. Function pointers to static member functions are done in the traditional 'C' style because there is no object pointer for this call required.
3047:
Important note: A function pointer always points to a function with a specific signature! Thus all functions, you want to use with the same function pointer, must have the same parameters and return-type!
3071:
If you want to use a member function as a callback function, then the member function needs to be associated with an object of the class before it can be called. In this case, you can use functor .
54:, which can be invoked and passed arguments just as in a normal function call. Such an invocation is also known as an "indirect" call, because the function is being invoked 443:
multiple times, adding together the values that the invoked function returns and returning the resulting sum. The two sums are written to the standard output by
1016:, functions are regarded as data, and can be passed, returned, and created dynamically directly by other functions, eliminating the need for function pointers. 966:
Functors, or function objects, are similar to function pointers, and can be used in similar ways. A functor is an object of a class type that implements the
977:
Many "pure" object-oriented languages do not support function pointers. Something similar can be implemented in these kinds of languages, though, using
3086: 3176: 982: 172:
takes one double-precision (double) parameter and returns another double, and is assigned to a function which converts centimeters to inches.
132: 73: 2129:
examples use this syntax. However, every C and C++ compiler supports a more clear and concise mechanism to declare function pointers: use
2125:
The C and C++ syntax given above is the canonical one used in all the textbooks - but it's difficult to read and explain. Even the above
3138: 3125: 3106: 178:
takes a pointer to a constant character array as well as an integer and returns a pointer to a character, and is assigned to a
66: 2957: 2151:// This declares 'F', a function that accepts a 'char' and returns an 'int'. Definition is elsewhere. 994: 971: 108: 43: 1019:
Extensively using function pointers to call functions may produce a slow-down for the code on modern processors, because a
1040:(usually referred to as member functions). Non-static member functions (instance methods) have an implicit parameter (the 1037: 986: 144: 978: 2196:// This defines 'fn', a variable of type pointer-to-'Fn', and assigns the address of 'F' to it. 1042: 1033: 124: 100: 3003: 3031: 2247:// This defines 'Call', a function that accepts a pointer-to-'Fn', calls it, and returns the result 65:
Function pointers allow different code to be executed at runtime. They can also be passed to a function to enable
1082:
In C++, in addition to the method used in C, it is also possible to use the C++ standard library class template
3160: 974:. They are also used as callback functions if it is necessary to use a member function as a callback function. 148: 112: 96: 2524:// Since there is no 'this', 'Fn' is the correct type; and 'fn' can be used as above. 3154: 2172:// This defines 'Fn', a type of function that accepts a 'char' and returns an 'int'. 2937: 967: 2836:// LEGACY: Note that to maintain existing code bases, the above definition style can still be used first; 2340:// LEGACY: Note that to maintain existing code bases, the above definition style can still be used first; 2947: 2304:// This calls function 'Call', passing in 'F' and assigning the result to 'call' 990: 3098: 2626:// This uses 'm' to call 'Member' in 'p', assigning the result to 'pA' 2590:// This uses 'm' to call 'Member' in 'c', assigning the result to 'cA' 3181: 2952: 1013: 76: 47: 3148: 2842:// This defines 'FnC', a type of pointer-to-member-of-class-'C' of type 'Fn' 1071: 439:
in turn invokes one of the two functions indirectly by dereferencing its function pointer argument
416: 182:
function which returns a pointer to the first occurrence of a given character in a character array.
2497:// This defines 'p', a pointer to 'C' and assigns the address of 'c' to it 1058:
Although function pointers in C and C++ can be implemented as simple addresses, so that typically
2962: 2223:// This calls 'F' using 'fn', assigning the result to the variable 'a' 998: 179: 1066:", typically two or three times the size of a simple function pointer, in order to deal with 2416:
These examples use the above definitions. In particular, note that the above definition for
1020: 2557:// "'m' is a pointer to member of class 'C' of type 'Fn'" 3142: 3135: 3129: 3110: 3102: 3090: 2983: 2942: 1067: 961: 3019:
Function Pointers are pointers, i.e. variables, which point to the address of a function
2548:// This defines 'm', a pointer-to-member-of-'C' with type 'Fn', 1006: 128: 3122: 3116: 245:// "strchr" is part of the C string handling (i.e., no need for declaration) 3170: 2141:
can actually be used is with a pointer - but that highlights the pointer-ness of it.
2659:// This defines 'Ref', a function that accepts a reference-to-'C', 17: 2752:// a pointer-to-member-of-'C' of type 'Fn', and a 'char', 2662:// a pointer-to-member-of-'C' of type 'Fn', and a 'char', 2137:
store the pointer as part of the definition. Note that the only way this kind of
2749:// This defines 'Ptr', a function that accepts a pointer-to-'C', 1063: 1002: 2425:// This defines 'C', a class with similar static and member functions, 51: 2839:// then the original type can be defined in terms of it using the new style. 2343:// then the original type can be defined in terms of it using the new style. 2220:// Note '&' not required - but it highlights what is being done. 827:// Use standard library function 'cos()' as the pointed-to function 770:// Use standard library function 'sin()' as the pointed-to function 3007: 884:// Use user-defined function 'square()' as the pointed-to function 123:
The simplest implementation of a function (or subroutine) pointer is as a
3060:"Expertise: Intermediate Language: C++: Use Functor for Callbacks in C++" 3035: 403:
The next program uses a function pointer to invoke one of two functions (
88: 165:
The following C program illustrates the use of two function pointers:
3059: 3089:, things to avoid with function pointers, some information on using 104: 587:// Use the function pointer 'funcp' to invoke the function 533:// Add values returned by the pointed-to function '*funcp' 140: 92: 84: 136: 80: 3117:
Member Function Pointers and the Fastest Possible C++ Delegates
2521:// This assigns a pointer-to-'Static' to 'fn'. 3149:
Secure Function Pointer and Callbacks in Windows Programming
2346:// This defines 'PFn', a type of pointer-to-type-Fn. 3095: 2863:// 'FnC' can be used wherever 'Fn C::*' can 248:// See https://en.wikipedia.org/C_string_handling#Functions 2551:// and assigns the address of 'C::Member' to it. 2364:// 'PFn' can be used wherever 'Fn *' can 2420:
can be used in pointer-to-member-function definitions:
1062:, member pointers in C++ are sometimes implemented as " 1055:(for an object or a pointer to object, respectively). 151:
generally implement function pointers in this manner.
464:// Function taking a function pointer as an argument 427:
twice, passing it a pointer to the library function
2554:// You can read it right-to-left like all pointers: 2428:// and then creates an instance called 'c' 131:of the function within executable memory. Older 1423: 1086:, of which the instances are function objects: 415:, computing an approximation of the function's 160: 46:referencing executable code, rather than data. 1860:// C++ only, same as: typedef int(*PFN)(int); 8: 2755:// calls the function and returns the result 2665:// calls the function and returns the result 419:). The program operates by having function 143:, as well as more modern languages such as 50:the function pointer yields the referenced 431:the first time, and a pointer to function 2337:// Again, '&' is not required 3157:, Function Pointers in C by "The C Book" 2974: 386:/* prints "5.905512 pedia" */ 62:through a fixed identifier or address. 3105:, a guide to C/C++ function pointers, 3119:, CodeProject article by Don Clugston 7: 411:) indirectly from another function ( 1418:Pointers to member functions in C++ 72:Function pointers are supported by 3151:, CodeProject article by R. Selvam 25: 3132:, C++ documentation and tutorials 1424:§ Alternate C and C++ syntax 161:§ Alternate C and C++ syntax 27:Pointer that points to a function 3032:"The Function Pointer Tutorials" 3004:"The Function Pointer Tutorials" 1012:In other languages that support 3177:Pointers (computer programming) 3163:, Function Pointer in dBASE dBL 3145:a visual guide of pointers in C 3161:Function Pointers in dBASE dBL 58:through a variable instead of 1: 2064:"Foo::negate(6) = " 2001:"Foo::mult(3,5) = " 1938:"Foo::add(2,4) = " 1364:"d/dx(x ^ 2) = " 1034:object-oriented programming 374:"Knowledge (XXG)" 101:object-oriented programming 3198: 3096:Function Pointer Tutorials 2121:Alternate C and C++ syntax 1421: 1060:sizeof(Fx)==sizeof(void *) 959: 435:the second time. Function 158: 133:third-generation languages 1032:C++ includes support for 3087:FAQ on Function Pointers 2422: 2148: 1431: 1088: 449: 185: 119:Simple function pointers 1005:function pointers with 3062:. DevX.com. 2005-01-31 3034:. logo. Archived from 3006:. logo. Archived from 2938:Delegation (computing) 1036:, so classes can have 968:function-call operator 2948:Higher-order function 1014:first-class functions 985:that define a single 923:"sum(square): %g 77:programming languages 3136:C pointers explained 2953:Procedural parameter 2963:Anonymous functions 1072:virtual inheritance 989:(member function). 417:Riemann integration 103:languages (such as 3141:2019-06-09 at the 3128:2009-04-05 at the 3101:2018-06-30 at the 2984:"Fortran Examples" 2982:Andrew J. Miller. 1100:<functional> 866:"sum(cos): %g 809:"sum(sin): %g 36:subroutine pointer 18:Subroutine pointer 3123:Pointer Tutorials 999:Visual Basic .NET 350:"%f %s" 180:C string handling 40:procedure pointer 16:(Redirected from 3189: 3111:function objects 3091:function objects 3074: 3073: 3068: 3067: 3056: 3050: 3049: 3044: 3043: 3028: 3022: 3021: 3016: 3015: 3000: 2994: 2993: 2991: 2990: 2979: 2927: 2924: 2921: 2918: 2915: 2912: 2909: 2906: 2903: 2900: 2897: 2894: 2891: 2888: 2885: 2882: 2879: 2876: 2873: 2870: 2867: 2864: 2861: 2858: 2855: 2852: 2849: 2846: 2843: 2840: 2837: 2834: 2831: 2828: 2825: 2822: 2819: 2816: 2813: 2810: 2807: 2804: 2801: 2798: 2795: 2792: 2789: 2786: 2783: 2780: 2777: 2774: 2771: 2768: 2765: 2762: 2759: 2756: 2753: 2750: 2747: 2744: 2741: 2738: 2735: 2732: 2729: 2726: 2723: 2720: 2717: 2714: 2711: 2708: 2705: 2702: 2699: 2696: 2693: 2690: 2687: 2684: 2681: 2678: 2675: 2672: 2669: 2666: 2663: 2660: 2657: 2654: 2651: 2648: 2645: 2642: 2639: 2636: 2633: 2630: 2627: 2624: 2621: 2618: 2615: 2612: 2609: 2606: 2603: 2600: 2597: 2594: 2591: 2588: 2585: 2582: 2579: 2576: 2573: 2570: 2567: 2564: 2561: 2558: 2555: 2552: 2549: 2546: 2543: 2540: 2537: 2534: 2531: 2528: 2525: 2522: 2519: 2516: 2513: 2510: 2507: 2504: 2501: 2498: 2495: 2492: 2489: 2486: 2483: 2480: 2477: 2474: 2471: 2468: 2465: 2462: 2459: 2456: 2453: 2450: 2447: 2444: 2441: 2438: 2435: 2432: 2429: 2426: 2419: 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: 2254: 2251: 2248: 2245: 2242: 2239: 2236: 2233: 2230: 2227: 2224: 2221: 2218: 2215: 2212: 2209: 2206: 2203: 2200: 2197: 2194: 2191: 2188: 2185: 2182: 2179: 2176: 2173: 2170: 2167: 2164: 2161: 2158: 2155: 2152: 2140: 2132: 2128: 2116: 2113: 2110: 2107: 2104: 2101: 2098: 2095: 2092: 2089: 2086: 2083: 2080: 2077: 2074: 2071: 2068: 2065: 2062: 2059: 2056: 2053: 2050: 2047: 2044: 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: 1951: 1948: 1945: 1942: 1939: 1936: 1933: 1930: 1927: 1924: 1921: 1918: 1915: 1912: 1909: 1906: 1903: 1900: 1897: 1894: 1891: 1888: 1885: 1882: 1879: 1876: 1873: 1870: 1867: 1864: 1861: 1858: 1855: 1852: 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: 1717: 1714: 1711: 1708: 1705: 1702: 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: 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: 1507: 1504: 1501: 1498: 1495: 1492: 1489: 1486: 1483: 1480: 1477: 1474: 1471: 1468: 1465: 1462: 1459: 1456: 1453: 1450: 1447: 1444: 1441: 1438: 1437:<iostream> 1435: 1413: 1410: 1407: 1404: 1401: 1398: 1395: 1392: 1389: 1386: 1383: 1380: 1377: 1374: 1371: 1368: 1365: 1362: 1359: 1356: 1353: 1350: 1347: 1344: 1341: 1338: 1335: 1332: 1329: 1326: 1323: 1320: 1317: 1314: 1311: 1308: 1305: 1302: 1299: 1296: 1293: 1290: 1287: 1284: 1281: 1278: 1275: 1272: 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: 1134: 1131: 1128: 1125: 1122: 1119: 1116: 1113: 1110: 1107: 1104: 1101: 1098: 1095: 1094:<iostream> 1092: 1085: 1061: 1054: 1050: 1021:branch predictor 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: 858: 855: 852: 849: 846: 843: 840: 837: 834: 831: 828: 825: 822: 819: 816: 813: 810: 807: 804: 801: 798: 795: 792: 789: 786: 783: 780: 777: 774: 771: 768: 765: 762: 759: 756: 753: 750: 747: 744: 741: 738: 735: 732: 729: 726: 723: 720: 717: 714: 711: 708: 705: 702: 699: 696: 693: 690: 687: 684: 681: 678: 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: 600: 597: 594: 591: 588: 585: 582: 579: 576: 573: 570: 567: 564: 561: 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: 446: 442: 438: 434: 430: 426: 422: 414: 410: 406: 399: 396: 393: 390: 387: 384: 381: 378: 375: 372: 369: 366: 363: 360: 357: 354: 351: 348: 345: 342: 339: 336: 333: 330: 327: 324: 321: 318: 315: 312: 309: 306: 303: 300: 297: 294: 291: 288: 285: 282: 279: 276: 273: 270: 267: 264: 261: 258: 255: 252: 249: 246: 243: 240: 237: 234: 231: 228: 225: 222: 219: 216: 213: 210: 207: 204: 203:/* for strchr */ 201: 200:<string.h> 198: 195: 194:/* for printf */ 192: 189: 74:third-generation 34:, also called a 32:function pointer 21: 3197: 3196: 3192: 3191: 3190: 3188: 3187: 3186: 3167: 3166: 3143:Wayback Machine 3130:Wayback Machine 3103:Wayback Machine 3083: 3078: 3077: 3065: 3063: 3058: 3057: 3053: 3041: 3039: 3030: 3029: 3025: 3013: 3011: 3002: 3001: 2997: 2988: 2986: 2981: 2980: 2976: 2971: 2943:Function object 2934: 2929: 2928: 2925: 2922: 2919: 2916: 2913: 2910: 2907: 2904: 2901: 2898: 2895: 2892: 2889: 2886: 2883: 2880: 2877: 2874: 2871: 2868: 2865: 2862: 2859: 2856: 2853: 2850: 2847: 2844: 2841: 2838: 2835: 2833:// Ptr(p, m, c) 2832: 2829: 2826: 2823: 2820: 2817: 2814: 2811: 2808: 2805: 2802: 2799: 2796: 2793: 2790: 2787: 2784: 2781: 2778: 2775: 2772: 2769: 2766: 2763: 2760: 2757: 2754: 2751: 2748: 2746:// Ref(r, m, c) 2745: 2742: 2739: 2736: 2733: 2730: 2727: 2724: 2721: 2718: 2715: 2712: 2709: 2706: 2703: 2700: 2697: 2694: 2691: 2688: 2685: 2682: 2679: 2676: 2673: 2670: 2667: 2664: 2661: 2658: 2655: 2652: 2649: 2646: 2643: 2640: 2637: 2634: 2631: 2628: 2625: 2622: 2619: 2616: 2613: 2610: 2607: 2604: 2601: 2598: 2595: 2592: 2589: 2586: 2583: 2580: 2577: 2574: 2571: 2568: 2565: 2562: 2559: 2556: 2553: 2550: 2547: 2544: 2541: 2538: 2535: 2532: 2529: 2526: 2523: 2520: 2517: 2514: 2511: 2508: 2505: 2502: 2499: 2496: 2493: 2490: 2487: 2484: 2481: 2478: 2475: 2472: 2469: 2466: 2463: 2460: 2457: 2454: 2451: 2448: 2445: 2442: 2439: 2436: 2433: 2430: 2427: 2424: 2417: 2414: 2409: 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: 2252: 2249: 2246: 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: 2138: 2130: 2126: 2123: 2118: 2117: 2114: 2111: 2108: 2105: 2102: 2099: 2096: 2093: 2090: 2087: 2084: 2081: 2078: 2075: 2072: 2069: 2066: 2063: 2060: 2057: 2054: 2051: 2048: 2045: 2042: 2039: 2036: 2033: 2030: 2027: 2024: 2021: 2018: 2015: 2012: 2009: 2006: 2003: 2000: 1997: 1994: 1991: 1988: 1985: 1982: 1979: 1976: 1973: 1970: 1967: 1964: 1961: 1958: 1955: 1952: 1949: 1946: 1943: 1940: 1937: 1934: 1931: 1928: 1925: 1922: 1919: 1916: 1913: 1910: 1907: 1904: 1901: 1898: 1895: 1892: 1889: 1886: 1883: 1880: 1877: 1874: 1871: 1868: 1865: 1862: 1859: 1856: 1853: 1850: 1847: 1844: 1841: 1838: 1835: 1832: 1829: 1826: 1823: 1820: 1817: 1814: 1811: 1808: 1805: 1802: 1799: 1796: 1793: 1790: 1787: 1784: 1781: 1778: 1775: 1772: 1769: 1766: 1763: 1760: 1757: 1754: 1751: 1748: 1745: 1742: 1739: 1736: 1733: 1730: 1727: 1724: 1721: 1718: 1715: 1712: 1709: 1706: 1703: 1700: 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: 1505: 1502: 1499: 1496: 1493: 1490: 1487: 1484: 1481: 1478: 1475: 1472: 1469: 1466: 1463: 1460: 1457: 1454: 1451: 1448: 1445: 1442: 1439: 1436: 1433: 1426: 1420: 1415: 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: 1210: 1207: 1204: 1201: 1198: 1195: 1192: 1189: 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: 1083: 1080: 1068:virtual methods 1059: 1052: 1048: 1030: 1028:Method pointers 964: 962:Function object 958: 953: 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: 856: 853: 850: 847: 844: 841: 838: 835: 832: 829: 826: 823: 820: 817: 814: 811: 808: 805: 802: 799: 796: 793: 790: 787: 784: 781: 778: 775: 772: 769: 766: 763: 760: 757: 754: 751: 748: 745: 742: 739: 736: 733: 730: 727: 724: 721: 718: 715: 712: 709: 706: 703: 700: 697: 694: 691: 688: 685: 682: 679: 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: 598: 595: 592: 589: 586: 583: 580: 577: 574: 571: 568: 565: 562: 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: 461:<stdio.h> 460: 457: 454: 451: 444: 440: 436: 432: 428: 424: 420: 412: 408: 404: 401: 400: 397: 394: 391: 388: 385: 382: 379: 376: 373: 370: 367: 364: 361: 358: 355: 352: 349: 346: 343: 340: 337: 334: 331: 328: 325: 322: 319: 316: 313: 310: 307: 304: 301: 298: 295: 292: 289: 286: 283: 280: 277: 274: 271: 268: 265: 262: 259: 256: 253: 250: 247: 244: 241: 238: 235: 232: 229: 226: 223: 220: 217: 214: 211: 208: 205: 202: 199: 196: 193: 191:<stdio.h> 190: 187: 163: 157: 127:containing the 121: 28: 23: 22: 15: 12: 11: 5: 3195: 3193: 3185: 3184: 3179: 3169: 3168: 3165: 3164: 3158: 3152: 3146: 3133: 3120: 3114: 3093: 3082: 3081:External links 3079: 3076: 3075: 3051: 3023: 2995: 2973: 2972: 2970: 2967: 2966: 2965: 2960: 2955: 2950: 2945: 2940: 2933: 2930: 2423: 2413: 2410: 2301:// Call(fn, c) 2149: 2146: 2143: 2122: 2119: 1432: 1419: 1416: 1089: 1079: 1076: 1029: 1026: 960:Main article: 957: 954: 455:<math.h> 450: 423:call function 186: 184: 183: 173: 156: 153: 120: 117: 26: 24: 14: 13: 10: 9: 6: 4: 3: 2: 3194: 3183: 3180: 3178: 3175: 3174: 3172: 3162: 3159: 3156: 3153: 3150: 3147: 3144: 3140: 3137: 3134: 3131: 3127: 3124: 3121: 3118: 3115: 3112: 3108: 3104: 3100: 3097: 3094: 3092: 3088: 3085: 3084: 3080: 3072: 3061: 3055: 3052: 3048: 3038:on 2011-05-16 3037: 3033: 3027: 3024: 3020: 3010:on 2011-05-16 3009: 3005: 2999: 2996: 2985: 2978: 2975: 2968: 2964: 2961: 2959: 2956: 2954: 2951: 2949: 2946: 2944: 2941: 2939: 2936: 2935: 2931: 2421: 2411: 2144: 2142: 2136: 2120: 1430: 1425: 1417: 1087: 1084:std::function 1077: 1075: 1073: 1069: 1065: 1056: 1045: 1044: 1039: 1035: 1027: 1025: 1022: 1017: 1015: 1010: 1008: 1004: 1000: 996: 992: 991:CLI languages 988: 984: 980: 975: 973: 969: 963: 955: 448: 418: 181: 177: 174: 171: 168: 167: 166: 162: 154: 152: 150: 146: 142: 138: 134: 130: 126: 118: 116: 114: 110: 106: 102: 98: 94: 90: 86: 82: 78: 75: 70: 68: 63: 61: 57: 53: 49: 48:Dereferencing 45: 41: 37: 33: 19: 3070: 3064:. Retrieved 3054: 3046: 3040:. Retrieved 3036:the original 3026: 3018: 3012:. Retrieved 3008:the original 2998: 2987:. Retrieved 2977: 2415: 2134: 2124: 1427: 1081: 1064:fat pointers 1057: 1041: 1031: 1018: 1011: 976: 965: 402: 293:cm_to_inches 209:cm_to_inches 175: 169: 164: 155:Example in C 122: 71: 64: 59: 55: 39: 35: 31: 29: 3182:Subroutines 2653:'A' 2620:'A' 2331:'A' 2241:'A' 893:compute_sum 836:compute_sum 779:compute_sum 470:compute_sum 437:compute_sum 425:compute_sum 413:compute_sum 380:'p' 3171:Categories 3155:The C Book 3113:(functors) 3066:2011-04-13 3042:2011-04-13 3014:2011-04-13 2989:2013-09-14 2969:References 1422:See also: 1370:derivative 1121:derivative 1001:implement 983:interfaces 979:references 159:See also: 56:indirectly 3107:callbacks 2145:C and C++ 1443:namespace 1106:namespace 1007:delegates 1003:type-safe 95:dBL, and 79:(such as 67:callbacks 3139:Archived 3126:Archived 3099:Archived 2932:See also 2097:<< 2067:<< 2061:<< 2049:<< 2004:<< 1998:<< 1986:<< 1941:<< 1935:<< 1434:#include 1394:<< 1367:<< 1361:<< 1130:function 1097:#include 1091:#include 993:such as 972:closures 956:Functors 458:#include 452:#include 197:#include 188:#include 135:such as 125:variable 60:directly 52:function 2958:Closure 2845:typedef 2349:typedef 2175:typedef 2139:typedef 2131:typedef 2127:typedef 1827:typedef 1782:Foo_pfn 1725:Foo_pfn 1710:typedef 1038:methods 129:address 89:Fortran 44:pointer 42:, is a 3109:, and 2884:Member 2815:->* 2806:return 2716:return 2644:->* 2584:Member 2542:Static 2470:Member 2452:Static 2446:static 2440:public 2283:return 2133:, but 2106:return 2091:negate 1893:return 1803:->* 1794:return 1686:->* 1677:return 1587:return 1569:negate 1563:static 1545:return 1497:return 1461:public 1403:return 1343:double 1313:return 1301:double 1292:double 1289:static 1244:return 1223:double 1202:double 1181:double 1169:double 1160:double 1142:double 1136:double 1118:double 1115:static 1078:In C++ 1053:->* 987:method 941:return 929:" 917:printf 899:square 872:" 860:printf 815:" 803:printf 761:double 725:return 713:double 707:square 704:double 671:return 635:double 590:double 518:double 506:double 497:double 491:double 476:double 467:double 389:return 344:printf 338:strchr 284:double 269:double 227:return 215:double 206:double 145:Pascal 111:, and 99:) and 2902:& 2875:& 2680:& 2575:& 2533:& 2512:& 2431:class 2385:CallP 2322:& 2211:& 2135:don't 2082:& 2034:& 2025:& 1971:& 1962:& 1851:-> 1452:class 1440:using 1151:& 1127:const 1103:using 680:101.0 644:funcp 605:100.0 566:<= 485:funcp 441:funcp 368:func2 356:func1 317:const 311:func2 278:func1 176:func2 170:func1 141:COBOL 93:dBASE 85:COBOL 2920:char 2893:RefP 2794:char 2704:char 2494:// C 2476:char 2458:char 2400:char 2316:Call 2310:call 2271:char 2253:Call 2187:char 2163:char 2100:endl 2070:bar3 2058:cout 2052:endl 2043:mult 2007:bar2 1995:cout 1989:endl 1944:bar1 1932:cout 1914:main 1866:bar3 1830:auto 1800:pFoo 1776:pFoo 1746:bar2 1683:pFoo 1638:pFoo 1608:bar1 1518:mult 1397:endl 1388:1e-5 1358:cout 1334:main 1238:eps2 1217:eps2 1184:eps2 1148:> 1133:< 1070:and 1043:this 997:and 752:void 746:main 445:main 421:main 362:15.0 320:char 299:char 260:void 254:main 236:2.54 147:and 139:and 137:PL/I 81:PL/I 2911:FnC 2890:int 2869:fnC 2866:FnC 2857:FnC 2854:::* 2785:::* 2761:Ptr 2758:int 2695:::* 2671:Ref 2668:int 2629:int 2593:int 2566:::* 2467:int 2449:int 2412:C++ 2391:PFn 2382:int 2370:pfn 2367:PFn 2358:PFn 2307:int 2250:int 2226:int 2178:int 2154:int 2085:Foo 2037:Foo 2028:foo 1980:add 1974:Foo 1965:foo 1926:foo 1923:Foo 1911:int 1896:pfn 1884:pfn 1881:PFN 1872:int 1863:int 1854:int 1845:int 1839:PFN 1806:pfn 1785:pfn 1770:Foo 1761:int 1752:int 1743:int 1737:int 1731:int 1722:::* 1719:Foo 1713:int 1689:pfn 1668:int 1662:int 1656:pfn 1653:::* 1650:Foo 1644:int 1632:Foo 1623:int 1614:int 1605:int 1575:int 1566:int 1533:int 1524:int 1515:int 1485:int 1476:int 1470:add 1467:int 1455:Foo 1446:std 1331:int 1280:eps 1190:eps 1172:eps 1109:std 1051:or 981:to 935:sum 911:1.0 905:0.0 887:sum 878:sum 854:1.0 848:0.0 842:cos 830:sum 821:sum 797:1.0 791:0.0 785:sin 773:sum 764:sum 743:int 674:sum 656:sum 569:100 545:for 536:int 527:0.0 521:sum 433:cos 429:sin 409:cos 407:or 405:sin 383:)); 329:int 251:int 115:). 105:C++ 38:or 3173:: 3069:. 3045:. 3017:. 2926:); 2881::: 2848:Fn 2827:); 2821:)( 2779:Fn 2740:); 2734:)( 2689:Fn 2656:); 2650:)( 2632:pA 2623:); 2617:)( 2596:cA 2581::: 2560:Fn 2539::: 2527:fn 2482:); 2464:); 2418:Fn 2406:); 2394:fn 2352:Fn 2334:); 2295:); 2286:fn 2265:fn 2259:Fn 2244:); 2235:fn 2205:fn 2199:Fn 2193:); 2181:Fn 2169:); 2088::: 2040::: 1977::: 1917:() 1905:); 1842:)( 1821:); 1809:)( 1740:); 1728:)( 1704:); 1692:)( 1671:)) 1659:)( 1602:}; 1337:() 1274:)) 1271:lo 1256:hi 1232:x0 1226:hi 1211:x0 1205:lo 1163:x0 1074:. 1049:.* 1009:. 995:C# 938:); 926:\n 914:); 881:); 869:\n 857:); 824:); 812:\n 800:); 698:); 695:lo 689:hi 659:+= 653:); 629:lo 620:lo 614:hi 578:++ 509:hi 500:lo 494:), 488:)( 447:. 365:), 314:)( 281:)( 230:cm 218:cm 109:C# 107:, 91:, 87:, 83:, 69:. 30:A 2992:. 2923:c 2917:, 2914:m 2908:, 2905:p 2899:C 2896:( 2887:; 2878:C 2872:= 2860:; 2851:C 2830:} 2824:c 2818:m 2812:p 2809:( 2803:{ 2800:) 2797:c 2791:, 2788:m 2782:C 2776:, 2773:p 2770:* 2767:C 2764:( 2743:} 2737:c 2731:m 2728:* 2725:. 2722:r 2719:( 2713:{ 2710:) 2707:c 2701:, 2698:m 2692:C 2686:, 2683:r 2677:C 2674:( 2647:m 2641:p 2638:( 2635:= 2614:m 2611:* 2608:. 2605:c 2602:( 2599:= 2587:; 2578:C 2572:= 2569:m 2563:C 2545:; 2536:C 2530:= 2518:; 2515:c 2509:= 2506:p 2503:* 2500:C 2491:; 2488:c 2485:} 2479:c 2473:( 2461:c 2455:( 2443:: 2437:{ 2434:C 2403:c 2397:, 2388:( 2379:; 2376:F 2373:= 2361:; 2355:* 2328:, 2325:F 2319:( 2313:= 2298:} 2292:c 2289:( 2280:{ 2277:) 2274:c 2268:, 2262:* 2256:( 2238:( 2232:= 2229:a 2217:; 2214:F 2208:= 2202:* 2190:c 2184:( 2166:c 2160:( 2157:F 2115:} 2112:; 2109:0 2103:; 2094:) 2079:, 2076:6 2073:( 2055:; 2046:) 2031:, 2022:, 2019:5 2016:, 2013:3 2010:( 1992:; 1983:) 1968:, 1959:, 1956:4 1953:, 1950:2 1947:( 1929:; 1920:{ 1908:} 1902:i 1899:( 1890:{ 1887:) 1878:, 1875:i 1869:( 1857:; 1848:) 1836:* 1833:( 1824:} 1818:j 1815:, 1812:i 1797:( 1791:{ 1788:) 1779:, 1773:* 1767:, 1764:j 1758:, 1755:i 1749:( 1734:, 1716:( 1707:} 1701:j 1698:, 1695:i 1680:( 1674:{ 1665:, 1647:( 1641:, 1635:* 1629:, 1626:j 1620:, 1617:i 1611:( 1599:} 1596:; 1593:i 1590:- 1584:{ 1581:) 1578:i 1572:( 1560:} 1557:; 1554:j 1551:* 1548:i 1542:{ 1539:) 1536:j 1530:, 1527:i 1521:( 1512:} 1509:; 1506:j 1503:+ 1500:i 1494:{ 1491:) 1488:j 1482:, 1479:i 1473:( 1464:: 1458:{ 1449:; 1412:} 1409:; 1406:0 1400:; 1391:) 1385:, 1382:x 1379:, 1376:f 1373:( 1355:; 1352:1 1349:= 1346:x 1340:{ 1328:} 1325:; 1322:x 1319:* 1316:x 1310:{ 1307:) 1304:x 1298:( 1295:f 1286:} 1283:; 1277:/ 1268:( 1265:f 1262:- 1259:) 1253:( 1250:f 1247:( 1241:; 1235:+ 1229:= 1220:; 1214:- 1208:= 1199:; 1196:2 1193:/ 1187:= 1178:{ 1175:) 1166:, 1157:, 1154:f 1145:) 1139:( 1124:( 1112:; 950:} 947:; 944:0 932:, 920:( 908:, 902:, 896:( 890:= 875:, 863:( 851:, 845:, 839:( 833:= 818:, 806:( 794:, 788:, 782:( 776:= 767:; 758:{ 755:) 749:( 740:} 737:; 734:x 731:* 728:x 722:{ 719:) 716:x 710:( 701:} 692:- 686:( 683:* 677:/ 668:} 665:; 662:y 650:x 647:( 641:= 638:y 632:; 626:+ 623:) 617:- 611:( 608:* 602:/ 599:i 596:= 593:x 584:{ 581:) 575:i 572:; 563:i 560:; 557:0 554:= 551:i 548:( 542:; 539:i 530:; 524:= 515:{ 512:) 503:, 482:* 479:( 473:( 398:} 395:; 392:0 377:, 371:( 359:( 353:, 347:( 341:; 335:= 332:) 326:, 323:* 308:* 305:( 302:* 296:; 290:= 287:) 275:* 272:( 266:{ 263:) 257:( 242:} 239:; 233:/ 224:{ 221:) 212:( 149:C 113:D 97:C 20:)

Index

Subroutine pointer
pointer
Dereferencing
function
callbacks
third-generation
programming languages
PL/I
COBOL
Fortran
dBASE
C
object-oriented programming
C++
C#
D
variable
address
third-generation languages
PL/I
COBOL
Pascal
C
§ Alternate C and C++ syntax
C string handling
Riemann integration
Function object
function-call operator
closures
references

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