Book contents
- Frontmatter
- Contents
- Acknowledgments
- Dedication
- 1 Introduction
- 2 From Source File to Executable File
- 3 Variables and Objects; Pointers and Addresses
- 4 Dynamic Allocation and Deallocation of Memory
- 5 Functions and Function Calls
- 6 One-Dimensional Arrays and Strings
- 7 Multi-Dimensional Arrays
- 8 Classes and Objects
- 9 Linked Data Structures
- 10 Memory Leaks and Their Debugging
- 11 Programs in Execution: Processes and Threads
- A Hanoi Towers Puzzle
- B Tracing Objects in C++
- C Tracing Objects and Memory in C++
- D Thread-Safe and Process - Safe Reporting and Logging Functions
- Glossary
- Index
5 - Functions and Function Calls
Published online by Cambridge University Press: 13 January 2010
- Frontmatter
- Contents
- Acknowledgments
- Dedication
- 1 Introduction
- 2 From Source File to Executable File
- 3 Variables and Objects; Pointers and Addresses
- 4 Dynamic Allocation and Deallocation of Memory
- 5 Functions and Function Calls
- 6 One-Dimensional Arrays and Strings
- 7 Multi-Dimensional Arrays
- 8 Classes and Objects
- 9 Linked Data Structures
- 10 Memory Leaks and Their Debugging
- 11 Programs in Execution: Processes and Threads
- A Hanoi Towers Puzzle
- B Tracing Objects in C++
- C Tracing Objects and Memory in C++
- D Thread-Safe and Process - Safe Reporting and Logging Functions
- Glossary
- Index
Summary
System stack, activation frame, activation frame as the storage for local auto objects and for function arguments. Passing arguments by value as opposed to by reference. Calling sequence. Recursion and its relation to activation frames and the system stack. The price of recursion.
Any program of even modest complexity must be modularized for many reasons: readability, testability, validation, extendibility, maintainability, and many others, all outside the scope of this book. However, we assume that the reader understands that any reasonable programming language must allow for some modularization; C and C++ are no exceptions. Besides modularization on the level of source files, virtually the only modularization feature of C consists of structuring a program into separate functions. The object orientation of C++ allows for a more complex and far better-controlled modularization.
A C/C++ function is a programming module with a precisely defined interface that consists of the function's header, which specifies the function's name, the data types of the arguments (the input to the function - though it is possible for a function not to have any arguments), and the data type of a single return value (the output of the function; again, it is possible for a function to return nothing at all). Let us observe that computer scientists prefer to speak of procedures (if no value is returned) and functions (if a value is returned and the execution has no “side effects”, meaning that it does not modify any data not local to the function).
- Type
- Chapter
- Information
- Memory as a Programming Concept in C and C++ , pp. 59 - 80Publisher: Cambridge University PressPrint publication year: 2003