c++ - 运行时解释器真的是 C 程序执行的一部分吗?

标签 c++ c iostream interpreter stdio

众所周知,C 是一种编译语言。根据C language Wikipedia它说:

它被设计为使用相对简单的编译器进行编译,提供对内存的低级访问,提供有效映射到机器指令的语言结构,并且需要最少的运行时支持。它还说,根据设计,C 提供了有效映射到典型机器指令的结构,因此它在以前用汇编语言编码的应用程序中得到了持久的使用,包括操作系统以及计算机的各种应用软件,包括: super 计算机到嵌入式系统。

但是当我读到this时& 根据 Bruce Eckel 的 Thinking in C++ 2,它在标题为 Iostreams 的第 2 章中说:(我省略了一些部分)

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链接还说:

  • 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 程序执行的一部分吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31187237/

相关文章:

c++ - 了解 C/C++ 中 Windows/MSVC 的一些 Antidebug 内联汇编

c++ - 为什么类计数器不增加 Coach 类?

c++ - C驱动编程蓝屏死机

c - 将参数传递给函数时 C 中的段错误

arrays - 在 C 的 while 循环中迭代 *str 与 str[]

C 空字符导致程序行为出现问题

c++ - 与不同架构上的数据对齐相关的问题是什么?

c++ - 我想更改 Cmd 字体样式

c++ - C++中二进制和txt模式有什么区别

c++ - 读取/显示实际字节 (C++)