前言(2)
本书组织
第1章,关于对象(Object Lessons),提供以对象为基础的观念背景,以及由C++(www.cppentry.com)提供的面向对象程序设计范式(paradigm。译注:关于paradigm这个字,请参阅本书第1章第22页的译注)。本章包括对对象模型的一个概述,说明目前普及的工业产品,但没有对于多重继承和虚拟继承有太靠近的观察(那是第3章和第4章的重头戏)。
第2章,构造函数语意学(The Semantics of Constructors),详细讨论constructor 如何工作。本章谈到constructors何时被编译器合成,以及给你的程序效率带来什么样的意义。
第3章至第5章是本书的重要内容。在这里,我详细地讨论了C++(www.cppentry.com)对象模型的细节。第3章,Data语意学(The Semantics of Data),讨论data members的处理。第4章,Function语意学(The Semantics of Function),专注于各式各样的member functions,并特别详细地讨论如何支持virtual functions。第5章,构造、析构、拷贝语意学(Semantics of Construction, Destruction, and Copy),讨论如何支持class模型,也讨论到object的生命期。每一章都有测试程序以及测试数据。我们对效率的预测,将拿来和实际结果做比较。
第6章,执行期语意学(Runtime Semantics),查看执行期的某些对象模型行为。包括临时性对象的生命及其死亡,以及对new运算符和delete运算符的支持。
第7章,在对象模型的尖端(On the Cusp of the Object Model),专注于exception handling、template support、runtime type identification。
预定的读者
本书可以扮演家庭教师的角色,不过它定位在中级以上的C++(www.cppentry.com)程序员,而非C++(www.cppentry.com)新手。我尝试提供足够的内容,使它能够被任何有点C++(www.cppentry.com)基础(例如读过我的C++(www.cppentry.com) Primer并有一些实际编程(www.cppentry.com)经验)的人接受。理想的读者是,曾经有过数年的C++(www.cppentry.com)编程(www.cppentry.com)经验,希望进一步了解"底层做些什么事"的人。书中某些部分甚至对于C++(www.cppentry.com)高手也具有吸引力,如临时性对象的产生,以及named return value(NRV)最佳化的细节等等。在与本书素材相同的各个公开演讲场合中,我已经证实了这些材料的吸引力。
程序范例及其执行
本书的程序范例主要有两个目的:
1. 为了提供书中所述C++(www.cppentry.com)对象模型各种概念的具体说明。
2. 提供测试,以测量各种语言性质的相对成本。
无论哪一种意图,都只是为了展现对象模型。举例而言,虽然我在书中有大量的举例,但我并非建议一个真实的3D graphic library必须以虚拟继承的方式来表现一个3D点(不过,你可以在[POKOR94]中发现作者Pokorny的确是这么做的)。
书中所有测试程序都在一部SGI Indigo2xL上编译执行,使用SGI 5.2 UNIX操作系统中的CC和NCC编译器。CC是cfront 3.0.1版(它会产生出C代码,再由一个C编译器重新编译为可执行文件)。NCC是Edison Design Group的C++(www.cppentry.com) front-end 2.19版,内含一个由SGI供应的程序代码产生器。至于时间测量,是采用UNIX的timex命令针对1 000万次迭代测试所得的平均值。
虽然在xL机器上使用这两个编译器,对读者而言可能觉得有些神秘,我却觉得对此书的目的而言,很好。不论是cfront或现在的Edison Design Group's C++(www.cppentry.com) front-end(Bjarne称其为"cfront的儿子"),都与平台无关。它们是一种一般化的编译器,被授权给34家以上的计算机制造商(其中包括Gray、SGI、Intel)和软件开发环境厂商(包括Centerline和Novell,后者是原先的UNIX软件实验室)。效率的测量并非为了对目前市面上的各家编译系统做评比,而只是为了提供C++(www.cppentry.com)对象模型之各种特性的一个相对成本测量。至于商业评比的效率数据,你可以在几乎任何一本计算机杂志的计算机产品检验报告中获得。
致谢
略
参考书目
注意:许多C++(www.cppentry.com) Report文章已被C++(www.cppentry.com) Gems收录,并由Stanley Lippman编辑完成,参见SIGS Books,New York,NY(1996)。
[BALL92] Ball, Michael, "Inside Templates", C++(www.cppentry.com) Report (September 1992)
[BALL93a] Ball, Michael, "What Are These Things Called Templates", C++(www.cppentry.com) Report (February 1993)
[BALL93b] Ball, Michael, "Implementing Class Templates", C++(www.cppentry.com) Report (September 1993)
[BOOCH93] Booch, Grady and Michael Vilot, "Simplifying the Booch Components", C++(www.cppentry.com) Report (June 1993)
[BORL91] Borland Language Open Architecture Handbook, Borland International Inc., Scotts Valley, CA
[BOX95] Box, Don, "Building C++(www.cppentry.com) Components Using OLE2", C++(www.cppentry.com) Report (March/April 1995)
[BUDD91] Budd, Timothy, An Introduction to Object-Oriented Programming, Addison-Wesley Publishing Company, Reading, MA(1991)
[BUDGE92] Budge, Kent G., James S. Peery, and Allen C. Robinson, "High Performance Scientific Computing Using C++(www.cppentry.com)", Usenix C++(www.cppentry.com) Conference Proceedings, Portland, OR(1992)
[BUDGE94] Budge, Kent G., James S. Peery, Allen C. Robinson, and Michael K. Wong, "Management of Class Temporaries in C++(www.cppentry.com) Translation Systems", The Journal of C Language Translation (December 1994)
[CARGILL95] Cargill, Tom, "STL Caveats, " C++(www.cppentry.com)Report (July/August 1993)
[CARROLL93] Carroll, Martin, "Design of the USL Standard Components", C++(www.cppentry.com) Report (June 1993)
[CARROLL95] Carroll, Martin, and Margaret A. Ellis, "Designing and Coding Reusable C++(www.cppentry.com), Addison-Wesley Publishing Company, Reading, MA(1995)
[CHASE94] Chase, David, "Implementation of Exception Handling, Part 1", The Journal of C Language Translation (June 1994)
[CLAM93a] Clamage, Stephen D., "Implementing New & Delete", C++(www.cppentry.com) Report (May 1993)
[CLAM93b] Clamage, Stephen D., "Beginnings & Endings", C++(www.cppentry.com) Report (September 1993)
[ELLIS90] Ellis, Margaret A. and Bjarne Stroustrup, The Annotated C++(www.cppentry.com) Reference Manual, Addison-Wesley Publishing Company, Reading, MA(1990)
[GOLD94] Goldstein, Theodore C. and Alan D. Sloane, "The Object Binary Interface - C++(www.cppentry.com) Objects for Evolvable Shared Class Libraries", Usenix C++(www.cppentry.com) Conference Proceedings, Cambridge, MA(1994)
[HAM95] Hamilton, Jennifer, Robert Klarer, Mark Mendell, and Brian Thomson, "Using SOM with C++(www.cppentry.com)", C++(www.cppentry.com) Report (July/August 1995)
[HORST95] Horstmann, Cay S., "C++(www.cppentry.com) Compiler Shootout", C++(www.cppentry.com) Report (July/August 1995)
[KOENIG90a] Koenig, Andrew and Stanley Lippman, "Optimizing Virtual Tables in C++(www.cppentry.com) Release 2.0", C++(www.cppentry.com) Report (March 1990)
[KOENIG90b] Koenig, Andrew and Bjarne Stroustrup, "Exception Handling for C++(www.cppentry.com) (Revised)", Usenix C++(www.cppentry.com) Conference Proceedings (April 1990)
[KOENIG93] Koenig, Andrew, "Combining C and C++(www.cppentry.com)", C++(www.cppentry.com) Report (July/August 1993)
[ISO-C++(www.cppentry.com)95] C++(www.cppentry.com) International Standard, Draft (April 28, 1995)
[LAJOIE94a] Lajoie, Josee, "Exception Handling: Supporting the Runtime Mechanism", C++(www.cppentry.com) Report (March/April 1994)
[LAJOIE94b] Lajoie, Josee, "Exception Handling: Behind the Scenes", C++(www.cppentry.com) Report (June 1994)
[LENKOV92] Lenkov, Dmitry, Don Cameron, Paul Faust, and Michey Mehta, "A Portable Implementation of C++(www.cppentry.com) Exception Handling", Usenix C++(www.cppentry.com) Conference Proceeding, Portland, OR(1992)
[LEA93] Lea, Doug, "The GNU C++(www.cppentry.com) Library", C++(www.cppentry.com) Report (June 1993)
[LIPP88] Lippman, Stanley and Bjarne Stroustrup, "Pointers to Class Members in C++(www.cppentry.com)", Implementor's Workshop, Usenix C++(www.cppentry.com) Conference Proceedings (October 1988)
[LIPP91a] Lippman, Stanley, "Touring Cfront", C++(www.cppentry.com) Journal, Vol.1, No.3 (1991)
[LIPP91b] Lippman, Stanley, "Touring Cfront: From Minutiae to Migraine", C++(www.cppentry.com) Journal, Vol.1, No.4 (1991)
[LIPP91c] Lippman, Stanley, C++(www.cppentry.com) Primer, Addison-Wesley Publishing Company, Reading, MA(1991)
[LIPP94a] Lippman, Stanley, "Default Constructor Synthesis", C++(www.cppentry.com) Report (January 1994)
[LIPP94b] Lippman, Stanley, "Applying The Copy Constructor, Part1: Synthesis", C++(www.cppentry.com) Report (February 1994)
[LIPP94c] Lippman, Stanley, "Applying The Copy Constructor, Part2", C++(www.cppentry.com) Report (March/April 1994)
[LIPP94d] Lippman, Stanley, "Objects and Datum", C++(www.cppentry.com) Report (June 1994)
[METAW94] MetaWare High C/C++(www.cppentry.com) Language Reference Manual, Metaware Inc., Santa Crus, CA(1994)
[MACRO92] Jones, David and Martin J. O'Riordan, The Microsoft Object Mapping, Microsoft Corporation, 1992
[MOWBRAY95] Mowbray, Thomas J. and Ron Zahavi, The Essential Corba, John Wiley & Sons, Inc. (1995)
[NACK94] Nackman, Lee R., and John J. Barton Scientific and Engineering C++(www.cppentry.com), An Introduction with Advanced Techniques and Examples, Addison-Wesley Publishing Company, Reading, MA(1994)
[PALAY92] Palay, Andrew J., "C++(www.cppentry.com) in a Changing Environment", Usenix C++(www.cppentry.com) Conference Proceedings, Portland, OR(1992)
[POKOR94] Pokorny, Cornel, Computer Graphics, Franklin, Beedle & Associates, Inc. (1994)
[PUGH90] Pugh, William and Grant Weddell, "Two-directional Record Layout for Multiple Inheritance", ACM SIGPLAN '90 Conference, White Plains, New York(1990)
[SCHMIDT94a] Schmidt, Douglas C., "A Domain Analysis of Network Daemon Design Dimensions", C++(www.cppentry.com) Report (March/April 1994)
[SCHMIDT94b] Schmidt, Douglas C., "A Case Study of C++(www.cppentry.com) Design Evolution", C++(www.cppentry.com) Report (July/August 1994)
[SCHWARZ89] Schwarz, Jerry, "Initializing Static Variables in C++(www.cppentry.com) Libraries", C++(www.cppentry.com) Report (February 1989)
[STROUP82] Stroustrup, Bjarne, "Adding Classes to C: An Exercise in Language Evolution", Software: Practices & Experience, Vol.13 (1983)
[STROUP94] Stroustrup, Bjarne, "The Design and Evolution of C++(www.cppentry.com)", Addison-Wesley Publishing Company, Reading, MA(1994)
[SUN94a] The C++(www.cppentry.com) Application Binary Interface, SunPro, Sun Microsystems, Inc.
[SUN94b] The C++(www.cppentry.com) Application Binary Interface Rationale, SunPro, Sun Microsystems, Inc.
[VELD95] Veldhuizen, Todd, "Using C++(www.cppentry.com) Template Metaprograms", C++(www.cppentry.com) Report (May 1995)
[VINOS93] Vinoski, Steve, "Distributed Object Computing with CORBA", C++(www.cppentry.com) Report (July/August 1993)
[VINOS94] Vinoski, Steve, "Mapping CORBA IDL into C++(www.cppentry.com)", C++(www.cppentry.com) Report (September 1994)
[YOUNG95] Young, Douglas, Object-Oriented Programming with C++(www.cppentry.com) and OSF/Motif, 2d ed., Prentice-Hall(1995)