Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么C语言有枚举类型,但没有 Pascal 的范围类型?在 Pascal 中,我们这样写:type index = 1...100;或者像这样: type letter = 'a'...'z';。
type index = 1...100;
type letter = 'a'...'z';
C 语言的设计者实现了一种非常简单的语言,其功能只是那些可以(大部分)直接翻译成一个或少数机器代码指令的功能。CPU 无法轻松完成的任何事情都必须通过函数调用来提供。
这使得编译器非常容易编写,并确保更容易看出性能问题可能出在哪里。
实现一个范围需要几个机器代码指令。此外,如果将其用作类型限定符,则意味着必须将范围检查添加到所有需要进一步机器代码指令的算术运算中。
除了通过函数调用(动态内存分配、字符串操作、映射等)之外,C 不支持其他语言支持的许多其他构造。