binding time

System designers often have a choice of when the system should make decisions about how to treat a feature; such a decision is called a binding. Usually, this boils down to making the decision at compile-time based solely on the program text (a static binding) or at run-time based on values computed by the program (a dynamic binding). Technically, we could refine these down to more categories.
  • at programming time (when the programmer writes the code)
  • at compile time
  • at link time (when the compiler assembles the executable file)
  • at load time (when the operating system starts the program)
  • at execution time (while the program is running)
The distinction between compile-time, link-time, and load-time is a relatively fine line, however, and we'll think of them all as compile-time decisions.
As an extremely simple example where binding time makes a difference, we could talk about when a value is bound to a subprogram parameter. In the line “puts("bindme");”, the value sent to puts is bound at programming time, when the programmer commits to sending the string bindme to the putsfunction. As you already know, imperative languages include a feature called a variable that allow this binding to occur at execution time. This allows programs to work with data given by the user, for example.
scanf("%d", &input_num);
printf("%d"input_num);
The compiler cannot determine the value sent to printf at compile-time, and so the binding will be deferred to run-time.
Binding-time decisions come up most often in relation to variables. Variables have several properties:
  • name
  • scope (area within the program where it can be used)
  • type
  • memory location
  • value
All of these properties could be determined at compile-time or run-time.

No comments:

Post a Comment