运行时解释器真的是 C 程序执行的一部分吗?
Is runtime interpreter really part of C program execution?
众所周知,C 是一种编译型语言。根据 C language Wikipedia 它说:
它被设计为使用相对简单的编译器进行编译,提供 low-level 内存访问,提供有效映射到机器指令的语言结构,并且需要最少的 run-time 支持。它还说,根据设计,C 提供了可以有效映射到典型机器指令的结构,因此它在以前用汇编语言编码的应用程序中找到了持久的用途,包括操作系统,以及各种计算机应用软件,范围从从超级计算机到嵌入式系统。
但是当我阅读 this & 根据 Bruce Eckel 的《Thinking in C++ 2》 它说在第 2 章标题为 Iostreams: (我省略了一些部分)
The big stumbling block is the runtime interpreter used for the
variable-argument list functions. This is the code that parses through
your format string at runtime and grabs and interprets arguments from
the variable argument list. It’s a problem for four reasons.
Because the interpretation happens at runtime there’s a performance
overhead you can’t get rid of. It’s frustrating because all the
information is there in the format string at compile time, but it’s
not evaluated until runtime. However, if you could parse the arguments
in the format string at compile time you could make hard function
calls that have the potential to be much faster than a runtime
interpreter (although the printf( ) family of functions is usually
quite well optimized).
this link 还说:
More type-safe: With , the type of object being I/O’d is
known statically by the compiler. In contrast, cstdio uses "%"
fields to figure out the types dynamically.
所以在阅读这篇文章之前,我在想解释器并没有用在像C这样的编译语言中,但是在C程序执行期间真的可以使用运行时解释器吗?在阅读本文之前我错了吗?与 Iostream 相比,这种运行时解释真的会产生这么多开销吗?
什么?
这不是代码的运行时解释,只是在使用格式化字符串的函数内部。
当然,他们必须遍历格式字符串以了解参数和所需的格式,这需要时间。
众所周知,C 是一种编译型语言。根据 C language Wikipedia 它说:
它被设计为使用相对简单的编译器进行编译,提供 low-level 内存访问,提供有效映射到机器指令的语言结构,并且需要最少的 run-time 支持。它还说,根据设计,C 提供了可以有效映射到典型机器指令的结构,因此它在以前用汇编语言编码的应用程序中找到了持久的用途,包括操作系统,以及各种计算机应用软件,范围从从超级计算机到嵌入式系统。
但是当我阅读 this & 根据 Bruce Eckel 的《Thinking in C++ 2》 它说在第 2 章标题为 Iostreams: (我省略了一些部分)
The big stumbling block is the runtime interpreter used for the variable-argument list functions. This is the code that parses through your format string at runtime and grabs and interprets arguments from the variable argument list. It’s a problem for four reasons.
Because the interpretation happens at runtime there’s a performance overhead you can’t get rid of. It’s frustrating because all the information is there in the format string at compile time, but it’s not evaluated until runtime. However, if you could parse the arguments in the format string at compile time you could make hard function calls that have the potential to be much faster than a runtime interpreter (although the printf( ) family of functions is usually quite well optimized).
this link 还说:
More type-safe: With , the type of object being I/O’d is known statically by the compiler. In contrast, cstdio uses "%" fields to figure out the types dynamically.
所以在阅读这篇文章之前,我在想解释器并没有用在像C这样的编译语言中,但是在C程序执行期间真的可以使用运行时解释器吗?在阅读本文之前我错了吗?与 Iostream 相比,这种运行时解释真的会产生这么多开销吗?
什么?
这不是代码的运行时解释,只是在使用格式化字符串的函数内部。
当然,他们必须遍历格式字符串以了解参数和所需的格式,这需要时间。