Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Indicate when each of the following bindings takes place in C++ (language design

ID: 3675006 • Letter: I

Question

Indicate when each of the following bindings takes place in C++ (language design time, language implementation time, compile time, link time, load time, or run time). If more than one time is possible, choose the latest possible time.

(a) Binding of the int type to a specific number of bytes (i.e., the decision to use a specific number of bytes to store an int value)

(b) Binding of a static variable declared inside a function to a specific memory address (c) Binding of a non-static variable declared inside a function to a specific memory address
(d) Binding of a variable to a specific type
(e) Binding of an operator to a specific number of operands
(f) Binding of a variable that has been declared const to a specific value

Explanation / Answer

a) Binding of the int type to a specific number of bytes
(i.e., the decision to use a specific number of bytes to store an int value)
Ans: complile time

b). Binding of a static variable declared inside a function to a specific memory address
Ans   : Load Time

(c) Binding of a non-static variable declared inside a function to a specific memory address
Ans:   Runtime
d). Binding of a variable to a specific type
Ans:   Compile time

(e) Binding of an operator to a specific number of operands
Ans:    bound at compile time, when types of operands are known
(f) Binding of a variable that has been declared const to a specific value
Ans: Load time

Theory:

Possible Binding Times
• Language design time -- bind operator symbols to operations
• Language implementation time-- bind floating point type to a representation
• Compile time -- bind a variable to a type in C or Java
• Load time -- bind a C or C++ static variable to a memory cell)
• Runtime -- bind a nonstatic local variable to a memory cell

The Concept of Binding
• The l-value of a variable is its address.
• The r-value of a variable is its value.
• A binding is an association, such as between an attribute and an entity,
or between an operation and a symbol.
• Binding time is the time at which a binding takes place.
• Possible binding times:
• Language design time: bind operator symbols to operations.
• For example, the asterisk symbol (*) is bound to the
multiplication operation.
• Language implementation time:
• A data type such as int in C is bound to a range of possible
values.
• Compile time: bind a variable to a particular data type at compile
time.
• Load time: bind a variable to a memory cell (ex. C static variables)
• Runtime: bind a nonstatic local variable to a memory cell.
Binding of Attributes to Variables
• A binding is static if it first occurs before run time and remains unchanged
throughout program execution.
• A binding is dynamic if it first occurs during execution or can change
during execution of the program.
Type Bindings
• If static, the type may be specified by either an explicit or an implicit
declaration.
Variable Declarations
• An explicit declaration is a program statement used for declaring the
types of variables.
• An implicit declaration is a default mechanism for specifying types of
variables (the first appearance of the variable in the program.)
• Both explicit and implicit declarations create static bindings to types.
• FORTRAN, PL/I, BASIC, and Perl provide implicit declarations.
• EX:
– In Fortran, an identifier that appears in a program that is not
explicitly declared is implicitly declared according to the following
convention:
I, J, K, L, M, or N or their lowercase versions is implicitly declared
to be Integer type; otherwise, it is implicitly declared as Real type.
– Advantage: writability.
– Disadvantage: reliability suffers because they prevent the
compilation process from detecting some typographical and
programming errors.
– In Fortran, vars that are accidentally left undeclared are given
default types and unexpected attributes, which could cause subtle
errors that, are difficult to diagnose.
• Less trouble with Perl: Names that begin with $ is a scalar, if a name
begins with @ it is an array, if it begins with %, it is a hash structure.
– In this scenario, the names @apple and %apple are unrelated.
• In C and C++, one must distinguish between declarations and definitions.
– Declarations specify types and other attributes but do no cause
allocation of storage. Provides the type of a var defined external to
a function that is used in the function.
– Definitions specify attributes and cause storage allocation.