中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > 综合其它
《Expert C Programming》笔记(1)
作者:未知 时间:2005-09-13 23:33 出处:Blog.ChinaUnix.net 责编:chinaitpower
              摘要:《Expert C Programming》笔记(1)

This book gathers together many other salutary stories. It records the wisdom of many experienced
programmers, to save the reader from having to rediscover everything independently. It acts as a guide
for territory that, while broadly familiar, still has some unexplored corners. There are extended
discussions of major topics like declarations and arrays/pointers, along with a great many hints and
mnemonics.

C is quirky, flawed, and an enormous success.
—Dennis Ritchie

Chapter 1. C Through the Mists of Time(穿过C时间表薄雾)

The type system was added primarily to help the compiler-writer distinguish floats, doubles, and
characters from words on the new PDP-11 hardware. This contrasts with languages like Pascal, where
the purpose of the type system is to protect the programmer by restricting the valid operations on a
data item. With its different philosophy, C rejects strong typing and permits the programmer to make
assignments between objects of different types if desired. The type system was almost an afterthought,
never rigorously evaluated or extensively tested for usability.


Many other features, besides the type system, were put in C for the C compiler-writer's benefit (and
why not, since C compiler-writers were the chief customers for the first few years). Features of C that
seem to have evolved with the compiler-writer in mind are:


1.Arrays start at 0 rather than 1.
  Most people start counting at 1, rather than zero. Compilerwriters
start with zero because we're used to thinking in terms of offsets.

2.The fundamental C types map directly onto underlying hardware. There is no built-in
complex-number type, as in Fortran, for example. The compiler-writer does not have to invest
any effort in supporting semantics that are not directly provided by the hardware. C didn't
support floating-point numbers until the underlying hardware provided it.

3.The auto keyword is apparently useless. It is only meaningful to a compiler-writer
making an entry in a symbol table-----it says this storage is automatically allocated on entering
the block (as opposed to global static allocation, or dynamic allocation on the heap). Auto is
irrelevant to other programmers, since you get it by default.

4Array names in expressions "decay" into pointers. It simplifies things to treat arrays as
pointers. We don't need a complicated mechanism to treat them as a composite object, or
suffer the inefficiency of copying everything when passing them to a function. But don't make
the mistake of thinking arrays and pointers are always equivalent.

5.Floating-point expressions were expanded to double-length-precision everywhere.
Although this is no longer true in ANSI C, originally real number constants were always
doubles, and float variables were always converted to double in all expressions. The reason,
though we've never seen it appear in print, had to do with PDP-11 floating-point hardware.
First, conversion from float to double on a PDP-11 or a VAX is really cheap: just append an
extra word of zeros. To convert back, just ignore the second word. Then understand that some
PDP-11 floating-point hardware had a mode bit, so it would do either all single-precision or
all double-precision arithmetic, but to switch between the two you had to change modes.
Since most early UNIX programs weren't floating-point-intensive, it was easier to put the box
in double-precision mode and leave it there than for the compiler-writer to try to keep track of
it!

6.No nested functions (functions contained inside other functions). This simplifies the
compiler and slightly speeds up the runtime organization of C programs.

7.The register keyword. This keyword gave the compiler-writer a clue about what
variables the programmer thought were "hot" (frequently referenced), and hence could
usefully be kept in registers. It turns out to be a mistake. You get better code if the compiler
does the work of allocating registers for individual uses of a variable, rather than reserving
them for its entire lifetime at declaration. Having a register keyword simplifies the
compiler by transferring this burden to the programmer.

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有