如何“大多数电脑直接支持”C数据类型? [英] How are C data types “supported directly by most computers”?

查看:138
本文介绍了如何“大多数电脑直接支持”C数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读K&放大器; R的的C程序设计语言的并在此声明是[简介,P  3]:

I am reading K&R's "The C Programming Language" and came across this statement [Introduction, p. 3]:

由于采用C提供的数据类型和控制结构由大多数计算机,实现自足程序所需的运行时库是很小的。直接支持

Because the data types and control structures provided by C are supported directly by most computers, the run-time library required to implement self-contained programs is tiny.

什么是加粗的语句是什么意思?有没有一种数据类型或控制结构的的例子并不的由计算机直接支持?

What does the bolded statement mean? Is there an example of a data type or a control structure that isn't supported directly by a computer?

推荐答案

是的,有不直接支持的数据类型。

Yes, there are data types not directly supported.

在许多嵌入式系统,没有硬件浮点单元。所以,当你写code是这样的:

On many embedded systems, there is no hardware floating point unit. So, when you write code like this:

float x = 1.0f, y = 2.0f;
return x + y;

它被翻译成这样的:

It gets translated into something like this:

unsigned x = 0x3f800000, y = 0x40000000;
return _float_add(x, y);

然后编译器或标准库必须提供 _float_add的实现(),它占用的内存嵌入式系统。如果你真是一个微小的系统上的计数字节,这样可以积少成多。

Then the compiler or standard library has to supply an implementation of _float_add(), which takes up memory on your embedded system. If you're counting bytes on a really tiny system, this can add up.

另外一个常见的​​例子是64位整数(长长 C标准自1999年起),不直接用32位系统的支持。旧SPARC系统不支持整数乘法,所以乘法不得不由运行时提供。还有其他的实施例。

Another common example is 64-bit integers (long long in the C standard since 1999), which are not directly supported by 32-bit systems. Old SPARC systems didn't support integer multiplication, so multiplication had to be supplied by the runtime. There are other examples.

相比之下,其他语言有更复杂的原语。

By comparison, other languages have more complicated primitives.

例如,一个Lisp符号需要大量的运行时支持,就像在Lua表,在Python,Fortran中的数组,等等。等效类型通常在C要么没有(没有标准符号或表)标准库的一部分,或者它们是更简单,不需要太多的运行时支持(在C数组基本上只是指针,空终止字符串几乎一样简单)。

For example, a Lisp symbol requires a lot of runtime support, just like tables in Lua, strings in Python, arrays in Fortran, et cetera. The equivalent types in C are usually either not part of the standard library at all (no standard symbols or tables) or they are much simpler and don't require much runtime support (arrays in C are basically just pointers, nul-terminated strings are almost as simple).

有一个显着的控制结构从C缺少的是异常处理。非局部退出仅限于的setjmp()的longjmp(),它只是保存和恢复处理器状态的某些部分。相比之下,C ++运行时有走栈,并调用析构函数和异常处理。

A notable control structure missing from C is exception handling. Nonlocal exit is limited to setjmp() and longjmp(), which just save and restore certain parts of processor state. By comparison, the C++ runtime has to walk the stack and call destructors and exception handlers.

这篇关于如何“大多数电脑直接支持”C数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆