Runtime vs Compile time

2018-12-31 13:48发布

Can anyone please give me a good understanding of whats the difference between run-time and compile-time?

25条回答
何处买醉
2楼-- · 2018-12-31 14:45

Translation of source code into stuff-happening-on-the-[screen|disk|network] can occur in (roughly) two ways; call them compiling and interpreting.

In a compiled program (examples are c and fortran):

  1. The source code is fed into another program (usually called a compiler--go figure), which produces an executable program (or an error).
  2. The executable is run (by double clicking it, or typing it's name on the command line)

Things that happen in the first step are said to happen at "compile time", things that happen in the second step are said to happen at "run time".

In an interpreted program (example MicroSoft basic (on dos) and python (I think)):

  1. The source code is fed into another program (usually called an interpreter) which "runs" it directly. Here the interpreter serves as an intermediate layer between your program and the operating system (or the hardware in really simple computers).

In this case the difference between compile time and run time is rather harder to pin down, and much less relevant to the programmer or user.

Java is a sort of hybrid, where the code is compiled to bytecode, which then runs on a virtual machine which is usually an interpreter for the bytecode.

There is also an intermediate case in which the program is compiled to bytecode and run immediately (as in awk or perl).

查看更多
登录 后发表回答