From cbf2f006fb4063cce55ca4e0bdc3e59fb0aa0d27 Mon Sep 17 00:00:00 2001 From: 2q1w2007 <2q1w2007@163.com> Date: Thu, 22 Jan 2015 23:07:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E9=A2=98=20How=20are=20C=20data=20typ?= =?UTF-8?q?es=20=E2=80=9Csupported=20directly=20by=20most=20computers?= =?UTF-8?q?=E2=80=9D=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... “supported directly by most computers”.md | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 sources/talk/20150122 How are C data types “supported directly by most computers”.md diff --git a/sources/talk/20150122 How are C data types “supported directly by most computers”.md b/sources/talk/20150122 How are C data types “supported directly by most computers”.md new file mode 100644 index 0000000000..0b57189252 --- /dev/null +++ b/sources/talk/20150122 How are C data types “supported directly by most computers”.md @@ -0,0 +1,53 @@ +How are C data types “supported directly by most computers”? +--------- + +#Q: + +I am reading K&R's *The C Programming Language*” and came across this statement [Introduction, p. 3]: + +>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? + +#A: + +Yes, there are data types not directly supported. + +On many embedded systems, there is no hardware floating point unit. So, when you write code like this: + +```C +float x = 1.0f, y = 2.0f; +return x + y; +``` + +It gets translated into something like this: + +```C +unsigned x = 0x3f800000, y = 0x40000000; +return _float_add(x, y); +``` + +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. + +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. + +##Other languages + +By comparison, other languages have more complicated primitives. + +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). + +##Control structures + +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. + +---- +via:[stackoverflow](http://stackoverflow.com/questions/27977522/how-are-c-data-types-supported-directly-by-most-computers/27977605#27977605) + +作者:[Dietrich Epp][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出 + +[a]:http://stackoverflow.com/users/82294/dietrich-epp \ No newline at end of file