Function Pointers
All C++ code is translated into some form of machine code, which resides in memory somewhere when a program is running (in the case of UnderC and Java, the machine code is for a virtual machine that runs on top of a real machine). So code is a form of data, and thus it has an address. Usually the operating system organizes it so that code occupies protected memory that can't be written to, but it can be read and executed. Applying the address-of operator (&) to a function reveals this address:
;> &sin; &cos;
(double operator(*)(double)) 72B364
(double operator(*)(double)) 72B390
This function address can be kept in a special kind of pointer, which can be used as a function. The dereference operator (*) is used to extract the ...
Get C++ By Example: UnderC Learning Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.