运行时和编译时的区别是什么?
当前回答
对于S.O.来说,这不是一个好问题(这不是一个特定的编程问题),但总的来说,这不是一个坏问题。
如果您认为这是微不足道的:那么读时与编译时的区别是什么呢?什么时候这是一个有用的区别?编译器在运行时可用的语言呢?Guy Steele(不是笨蛋,他)在CLTL2中写了7页关于EVAL-WHEN的内容,CL程序员可以使用它来控制这一点。两句话只能勉强给出一个定义,而定义本身还远远不够解释。
In general, it's a tough problem that language designers have seemed to try to avoid. They often just say "here's a compiler, it does compile-time things; everything after that is run-time, have fun". C is designed to be simple to implement, not the most flexible environment for computation. When you don't have the compiler available at runtime, or the ability to easily control when an expression is evaluated, you tend to end up with hacks in the language to fake common uses of macros, or users come up with Design Patterns to simulate having more powerful constructs. A simple-to-implement language can definitely be a worthwhile goal, but that doesn't mean it's the end-all-be-all of programming language design. (I don't use EVAL-WHEN much, but I can't imagine life without it.)
关于编译时和运行时的问题空间是巨大的,而且在很大程度上仍未被探索。这并不是说S.O.是进行讨论的正确场所,但我鼓励人们进一步探索这一领域,特别是那些对它应该是什么没有先入为主概念的人。这个问题既不简单也不愚蠢,我们至少可以给检察官指出正确的方向。
不幸的是,我不知道任何好的参考资料。CLTL2稍微讲了一下,但对于学习它并不是很好。
其他回答
Imagine that you are a boss and you have an assistant and a maid, and you give them a list of tasks to do, the assistant (compile time) will grab this list and make a checkup to see if the tasks are understandable and that you didn't write in any awkward language or syntax, so he understands that you want to assign someone for a Job so he assign him for you and he understand that you want some coffee, so his role is over and the maid (run time)starts to run those tasks so she goes to make you some coffee but in sudden she doesn’t find any coffee to make so she stops making it or she acts differently and make you some tea (when the program acts differently because he found an error).
将源代码转换为“屏幕|磁盘|网络”可以(大致)以两种方式发生;称之为编译和解释。
在编译程序中(例如c和fortran):
源代码被输入到另一个程序(通常称为编译器),该程序生成一个可执行程序(或一个错误)。 运行可执行文件(通过双击它,或在命令行上键入它的名称)
在第一步发生的事情被称为在“编译时”发生,在第二步发生的事情被称为在“运行时”发生。
在解释程序中(例如MicroSoft basic(在dos上)和python(我想)):
源代码被输入到另一个程序(通常称为解释器),该程序直接“运行”它。在这里,解释器充当程序和操作系统(或非常简单的计算机中的硬件)之间的中间层。
在这种情况下,编译时和运行时之间的差异很难确定,而且与程序员或用户的关系也小得多。
Java是一种混合,代码被编译成字节码,然后在虚拟机上运行,虚拟机通常是字节码的解释器。
还有一种中间情况,即程序被编译为字节码并立即运行(如在awk或perl中)。
运行时是指在运行程序时发生的事情。
编译时是指在编译程序时发生的事情。
这里有一个非常简单的答案:
Runtime and compile time are programming terms that refer to different stages of software program development. In order to create a program, a developer first writes source code, which defines how the program will function. Small programs may only contain a few hundred lines of source code, while large programs may contain hundreds of thousands of lines of source code. The source code must be compiled into machine code in order to become and executable program. This compilation process is referred to as compile time.(think of a compiler as a translator)
用户可以打开并运行编译后的程序。当应用程序正在运行时,它被称为运行时。
术语“运行时”和“编译时”经常被程序员用来指代不同类型的错误。编译时错误是一种问题,例如语法错误或缺少文件引用,从而阻止程序成功编译。编译器产生编译时错误,并通常指出源代码的哪一行导致了问题。
如果一个程序的源代码已经被编译成一个可执行程序,那么它在程序运行时可能仍然有错误。例子包括不能工作的特性、意外的程序行为或程序崩溃。这些类型的问题被称为运行时错误,因为它们发生在运行时。
参考
嗯,好吧,运行时是用来描述程序运行时发生的事情。
编译时间用来描述在构建程序(通常由编译器)时发生的事情。