- Binding : Compiler determines a location in memory
- Variable names bound to their
storage memory address (offset)
- Function names bound to their
starting memory address (offset)
- Two kinds of binding
:
- Compile-Time Binding
- Compiler has enough information to determine an address (offset)
- Executable code contains address references
- Run-Time Binding
- Compiler can’t determine an address (offset)
- Determination of address occurs as program executes
- Executable code must calculate (dereference) address
- Variables have their addresses hardcoded during compilation
- Global
variables given offset from start of global data area
- Local
variables given offset from top of stack
- Object
variables given offset from start of object data
- Function calls are hardcoded during compilation
, compiler is able to determine which function matches each call
- Functions
have specific starting address in object file
- Object methods
have specific starting address in object file
- Pointers prevent binding during compilation
- Pointer to
dynamic memory
address not known until allocated
- Pointer to
memory
address not known until assigned
- Pointer to
function
address not known until assigned
- Pointer to
object
not known until assigned
- Methods and pointers to objects
- Normal methods are compile-time bound to class of pointer
- Special methods are run-time bound to class of current object
- Compile-Time Binding
- Data type of pointer determines which method is invoked
- Occurs for ALL
non-virtual methods
- Potential problem
- base class method invoked for derived class objects
- Run-Time Binding
- Type of the object the pointer is pointing to determines which
method is invoked
- Occurs for ALL
virtual
functions
- Assures getting correct method for an object