binding to a parameter

What does the term "binding to a parameter" mean? What happens in the background?

For eg. During function call with a type mismatch a temp object is created and bound to the parameter in called function, in order for function call to succeed. Ofcourse, this occurs only if the type conversion is possible.

I surmise one of the following:
- Copying by value
- Some kind of hash association
You are talking about general computing. In simplest terms:

A parameter is the name for the name and type of some thing which modifies the operation of your function. In C and C++ the terminology is "argument name" and "argument type".

An argument is the actual value used for said modification (of the specified type and referenced via the given name). In C and C++ the terminology is "argument value".

To "bind" values to names is simply saying that 'name' now references 'value'. It is equivalent to the statement name = value;

As a concrete example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <cmath>
#include <iostream>
using namespace std;

//
// n and v are the parameter names.
//
double log_n( double n, double v )
  {
  return std::log( v ) / std::log( n );
  }

int main()
  {
  double base, value;
  cout << "Logarithm calculator\n";

  cout << "What base> " << flush;
  cin >> base;

  cout << "What value> " << flush;
  cin >> value;

  cout << "The log " << base << " ( " << value << " ) is "

       //
       // base and value are the argument values.
       //
       << log_n( base, value )

       << endl;
  return 0;
  }


The way in which the value is bound depends on several things.

You can bind by copy (as in the above example).
You can bind by reference (as in double & name).

The actual value is stored somewhere in memory just as any other value. Where exactly depends on a lot of specifics, but for simple values (like int and double) you can generally assume that they are in a CPU register or on the stack. In the case of structured types (like classes) what is actually on the stack/in the register is a pointer to the object. Some compilers will optimize the object directly on the stack or even in a machine word -- but this is behind the scenes trickery that really has nothing to do with your question.

Hope this helps.

[edit]
BTW, I should add that references are really just pointers -- so the pointer value is passed behind the scenes, but because the language automatically dereferences it (hence, it is a "reference") the name is bound to the referenced object, not the reference itself.
Last edited on
That helps. Thanks!
Topic archived. No new replies allowed.