深入计算机系统:1.1 Information Is Bits + Context(1.1 信息就是位+的上下文)

信息就是位+的上下文

 

从C语言的生命周期源头说起,结合列举的简单C语言程序的Main函数,底层都是一串由0和1组成的比特,每8位组成一个字节,每个字节都代表着这段程序的字符,每个字符的对应关系大多由ASCII组合成,如#=35 i=105。这段程序表明所有信息都在系统中,文件存放在硬盘,程序和对应的用户数据存储在内存,数据交换在网络中,这一切都是这么一串比特表示的。区别他们的唯一方法就是联系上下文,因为他们有可能代表整型、浮点型、字符串或机器指令。作为程序员,我们有必须清楚了解计算机机器的表示方法,同样的数字表示可能跟实际的值不一样。

 

C编程语言的起源

c语言起源于1969-1973的贝尔实验室,ANSI(美国国家标准学会)在1989年发布了C语言的标准,后来又变成了ISO(国际标准组织)的责任。这份标准定义了一系列的函数库,称为C语言标准库。Kernighan和Ritchie在他们的经典书籍K&R中描述了关于C语言的ANSI标准,Ritchie说C语言是古怪的、缺陷的、成功的。为什么说是成功的呢?

-C语言与Unix操作系统紧密相连

-C是小而简单的编程语言

-C是用于实践的编程语言

C语言是系统层级编程的最好选择,同时也是应用级层面的选择。但是不是所有程序员和解决方案都适用,如C语言指针造成的困惑和错误就是其中之一,另外,它也不支持非常有用的抽象支持,如类、对象、异常等。

新的编程语言如C++,JAVA就针对这种应用程序的情况有了新的解决方案

 

 Our hello program begins life as a source program (or source file)that the programmer creates with an editor and saves in a text filecalled hello.c. The source program is a sequence of bits, each witha value of 0 or 1, organized in 8-bit chunks called bytes. Each byte represents some text character in the program.

 

 Most computer systems represent text characters using the ASCII standard that represents each character with a unique byte-size integer value. For example,1Figure 1.2shows the ASCIIrepresentation of thehello.cprogram.

 

1.1 Information Is Bits + Context

Other encoding methods are used to represent text in non-English languages.See the aside on page 50 for a discussion on this.

The hello.c program is stored in a file as a sequence of bytes. Each byte has an integer value that corresponds to some character. Forexample, the first byte has the integer value 35, which corresponds to the character ` # '. The second byte has the integer value 105, which corresponds to the character 'i' , and so on. Notice that each textline is terminated by the invisible newline character `\n' , which is represented by the integer value 10. Files such as hello.c that consist exclusively of ASCII characters are known as text files. Allother files are known as binary files.

The representation of hello.c illustrates a fundamental idea: All information in a system—including disk files, programs stored in memory, user data stored in memory, and data transferred across a network—is represented as a bunch of bits. The only thing that distinguishes different data objects is the context in which we view them. For example, in different contexts, the same sequence of bytes might represent an integer, floating-point number, character string, or machine instruction.

As programmers, we need to understand machine representations of numbers because they are not the same as integers and real numbers. They are finite

Aside Origins of the C programming language

C was developed from 1969 to 1973 by Dennis Ritchie of Bell Laboratories. The American National Standards Institute(ANSI) ratified the ANSI
C standard in 1989, and this standardization later became the responsibility of the International Standards Organization (ISO). The standard define the C language and a set of library functions known asthe C standard library. Kernighan and Ritchie describe ANSI C in their classic book, which is known affectionately as "K&R"[61]. In Ritchie's words [92], C is "quirky, flawed, and an enormous success." So why the success?

1.C was closely tied with the Unix operating system. C was developed from the beginning as the system programming language for Unix. Most of the Unix kernel (the core part of the operating system), and all of its supporting tools and libraries, were written in C. As Unix became popular in universities in the late 1970s and early 1980s, many people were exposed to C and found that they liked it. Since Unix was written almost entirely in C, it could be easily ported to new machines, which created an even wider audience for both C and Unix.


2.C is a small, simple language. The design was controlled by a single person, rather than a committee, and the result was a clean, consistent design with little baggage. The K&R book describes the complete language and standard library, with numerous examples and exercises, in only 261 pages. The simplicity of C made it relatively easy to learn and to port to different computers.


3.C was designed for a practical purpose. C was designed to implement the Unix operating system. Later, other people found that they could write the programs they wanted,without the language getting in the way
C is the language of choice for system-level programming, and there is a huge installed base of application-level programs as well. However, it is not perfect for all programmers and all situations. C pointers are a common source of confusion and programming errors. C also lacks explicit support for useful abstractions such as classes, objects, and exceptions. Newer languages such as C++ and Java address these issues forapplication-level programs.
approximations that can behave in unexpected ways. Thifundamental idea is explored in detail in Chapter 2 .

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值