Friday, March 25, 2011

Difference between compile time and run time

The difference between compile time and run time is known as the "phase distinction." To understand how a program behaves in each phase, it is helpful to evaluate its invariants, potential errors, postconditions, and inputs/outputs.

Compile Time

  • Invariants: The program does not need to satisfy any invariants and does not even need to be well-formed initially.

  • What Can Go Wrong:

    • Syntax errors

    • Typechecking errors

    • Compiler crashes (rare)

  • Postconditions (If Successful):

    • The program is deemed well-formed.

    • It is ready to be executed (though it may still fail upon running).

  • Inputs and Outputs:

    • Inputs: The source code, along with necessary header files, interfaces, and imported libraries.

    • Outputs: Assembly code, relocatable object code, an executable program, or error messages if compilation fails.

Run Time

  • Invariants: The environment assumes nothing; invariants are solely enforced by the programmer's logic.

  • What Can Go Wrong:

    • Fatal run-time errors: Division by zero, dereferencing a null pointer, or running out of memory.

    • Program-handled errors: Attempting to open a missing file or processing a malformed URL.

  • Postconditions (If Successful): The program successfully finishes its tasks or continues operating without crashing.

  • Inputs and Outputs: Entirely dictated by the programmer. This includes interacting with files, UI windows, network packets, or external hardware (which only occurs during run time).

No comments: