Uninitialized Variable - Use in Languages

Use in Languages

Uninitialized variables are a particular problem in languages such as assembly language, C, and C++, which were designed for systems programming. The development of these languages involved a design philosophy in which conflicts between performance and safety were generally resolved in favor of performance. The programmer was given the burden of being aware of dangerous issues such as uninitialized variables.

In other languages, variables are often initialized to known values when created. Examples include:

  • VHDL initializes all standard variables into special 'U' value. It is used in simulation, for debugging, to let the user to know when the don't care initial values, through the multivalued logic, affect the output.
  • Java does not have uninitialized variables. Fields of classes and objects that do not have an explicit initializer and elements of arrays are automatically initialized with the default value for their type (false for boolean, 0 for all numerical types, null for all reference types). Local variables in Java must be definitely assigned to before they are accessed, or it is a compile error.
  • Python initializes local variables to NULL (distinct from None) and raises an UnboundLocalError when such a variable is accessed before being (re)initialized to a valid value.
  • D initializes all variables unless explicitly specified by the programmer not to.

Even in languages where uninitialized variables are allowed, many compilers will attempt to identify uninitialized variables and report them as compile-time errors.

Read more about this topic:  Uninitialized Variable

Famous quotes containing the word languages: