Programming System Scope And Scope

Submitted By Chris3257
Words: 301
Pages: 2

1-29
BINDINGS & SCOPE
Variables
• Name (dynamic and alloc variables can be anonymous) where x is the pointer to the value.
• Address
• Value
• Type
• Lifetime - period of time when variable exist.
• Scope – the portion of code which can access the variable)

Binding time
• Design Time
• Compile Time
• Link Time
• Run Time x = 10; (Python does more things at run time[types at run time so variables can change types])
C++ binds functions at link time unless you force it to run at run time by making function virtual.

Static vs Dynamic Type Binding

Static – types bound at compile time Dynamic – types bound at run time Explicit type binding Programmer tells what the types are
Implicit type Programmer does not have to tell the types. (Hascal, Python) Compiler determines the types.

Dynamic Type Binding Compiler waits until program runs and then determines what the type is. Good:
• Templates are included
• Easier to write Problems:
• Typos become new variables and are not errors
• May have a type error but may not know for many tests
• Harder to read

Storage – where variables are located in memory during execution. Allocation – when a variable is bound to a memory location Deallocation – when a variable is unbound
Stack 

Why put variable on heap instead of stack?
- Things on the stack has a lifetime that is only the stack’s lifetime.
- When you don’t know how big the object is. (Big Int in C++ when you must use