pythoncrubybinding

Is this statically bound?


Say that I have a C program and it has this line:

int a = 12;

Is the value of 12 bound to 'a' during compile time? Or is the value placed into memory during run time when the scope of the program hits 'a'?

What about programming languages like Python and Ruby?

Are there languages/instances where a value is statically bound to a variable? I've been thinking about this for a while now and I honestly can't think of a logical reason for statically binding a value to a primitive type.


Solution

  • The value 12 is not statically bound to a. Rather, a is bound to a memory location, which is initialized to the value 12.

    If a were declared as const and nothing ever took the address of it, the compiler would not need to allocate storage and may use it as a compile-time constant, in which case the value 12 would be statically bound to a.