Function Pointers and Callbacks
Data on the stack has a location—also called an address. So does data on the heap. And so does every line of code in your program. In fact, when you read about “the flow of control,” you should actually think of a variable used by the operating system to keep track of which instruction of the program is being performed. Top-to-bottom control flow is just like moving through an array using an index or pointer.
In fact, a program to run programs might look something like Listing 15.4.
Listing 15.4. Outline of a Program to Run Programs
1: struct anInstruction 2: { 3: anInstructionCode InstructionCode; 4: anInstruction *NextInstruction; 5: } ; 6: 7: anInstruction *Program = 8: new anInstruction[NumberOfInstructions]; ... |
Get SAMS Teach Yourself C++ in 10 Minutes SECOND 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.