logo资料库

B Stroustrup-The design andevolution of C _ Reading, Mass. Addison-Wesley _ 1994 repr.1995-Addison-Wesley (1994).pdf

第1页 / 共474页
第2页 / 共474页
第3页 / 共474页
第4页 / 共474页
第5页 / 共474页
第6页 / 共474页
第7页 / 共474页
第8页 / 共474页
资料共474页,剩余部分请下载后查看
Preface
Contents
Notes to the Reader
Part I
1 The Prehistory of C++
1.1 Simula and Distributed Systems
1.2 C and Systems Programming
1.3 General Background
2 C with Classes
2.1 The Birth of C with Classes
2.2 Feature overview
2.3 Classes
2.4 Run-Time Efficiency
2.5 The Linkage Model
2.6 Static Type Checking
2.7 Why C?
2.8 Syntax Problems
2.9 Derived Classes
2.10 The Protection Model
2.11 Run-Time Guarantees
2.12 Minor Features
2.13 Features Considered, but not Provided
3 The Birth of C++
3.1 From C with Classes to C++
3.2 Aims
3.3 Cfront
3.4 Language Features
3.5 Virtual Functions
3.6 Overloading
3.7 References
3.8 Constants
3.9 Memory Managament
3.10 Type Checking
3.11 Minor Features
3.12 Relationship to Classic C
3.13 Tools for Language Design
3.14 The C++ Programming Language(1st edition)
3.15 The Whatis? Paper
4 C++ Language Design Rules
4.1 Rules and Principles
4.2 General Rules
4.3 Design Support Rules
4.4 Language-Technical Rules
4.5 Low-Level Programming Support Rules
4.6 A Final Word
5 Chronology 1985-1993
5.1 Introduction
5.2 Release 2.0
5.3 The Annotated Reference Manual
5.4 ANSI and ISO Standardization
6 Standardization
6.1 What is a Standard?
6.2 How does the Committee Operate?
6.3 Clarifications
6.4 Extensions
6.5 Examples of Proposed Extensions
7 Interest and Use
7.1 The Explosion in Interest and Use
7.2 Teaching and Learning C++
7.3 Users and Applications
7.4 Commercial Competition
8 Libraries
8.1 Introduction
8.2 C++ Library Design
8.3 Early Libraries
8.4 Other Libraries
8.5 A Standard Library
9 Looking Ahead
9.1 Introduction
9.2 Retrospective
9.3 Only a Bridge?
9.4 What Will Make C++ Much More Effective?
Part II
10 Memory Managemant
10.1 Introduction
10.2 Separating Allocation and Initialization
10.3 Array Allocation
10.4 Placement
10.5 Deallocation Problems
10.6 Memory Exhaustion
10.7 Automatic Garbage Collection
11 Overloading
11.1 Introduction
11.2 Overload Resolution
11.3 Type-Safe Linkage
11.4 Object Creation and Copying
11.5 Notational Convenience
11.6 Adding Operators to C++
11.7 Enumerations
12 Multiple Inheritance
12.1 Introduction
12.2 Ordinary Base Classes
12.3 Virtual Base Classes
12.4 The Object Layout Model
12.5 Method Combination
12.6 The Multiple Inheritance Controversy
12.7 Delegation
12.8 Renaming
12.9 Base and Member Initializers
13 Class Concept Refinements
13.1 Introduction
13.2 Abstract Classes
13.3 const Member Functions
13.4 Static Member Functions
13.5 Nested Classes
13.6 Inherited::
13.7 Relaxation of Overriding Rules
13.8 Multi-methods
13.9 Protected Members
13.10 Improved Code Generation
13.11 Pointers to Members
14 Casting
14.1 Major Extensions
14.2 Run-Time Type Information
14.3 A New Cast Notation
15 Templates
15.1 Introduction
15.2 Templates
15.3 Class Templates
15.4 Constraints on Template Arguments
15.5 Avoiding Code Replication
15.6 Function Templates
15.7 Syntax
15.8 Composition Techniques
15.9 Template Class Relationships
15.10 Template Instantiation
15.11 Implication of Templates
16 Exception Handling
16.1 Introduction
16.2 Aims and Assumptions
16.3 Syntax
16.4 Grouping
16.5 Resource Management
16.6 Resumption vs. Termination
16.7 Asynchronous Events
16.8 Multi-level Propagation
16.9 Static Checking
16.10 Invariants
17 Namespaces
17.1 Introduction
17.2 The Problem
17.3 Ideals for a Solution
17.4 The Solution: Namespaces
17.5 Implications for Classes
17.6 C Compatibility
18 The C Preprocessor
18.1 Cpp
Index
The Design and Evolution of C++ Bjarne Stroustrup AT&T Bell Laboratories Murray Hill, New Jersey •TT ADDISON-WESLEY PUBLISHING COMPANY Reading, Massachusetts · Menlo Park, California · New York Don Mills, Ontario · Wokingham, England · Amsterdam · Bonn • Sydney Singapore · Tokyo · Madrid · San Juan · Milan · Paris
Library of Congress Cataloging-in-Publication Data Stroustrup, Bjame. The Design and Evolution of C++ / Bjame Stroustrup. p. em. Includes bibliographical references and index. ISBN 0-201-54330-3 1. C++ (Computer program language) I. Title. II. Title: Design and Evolution of C plus plus. QA76.73.C153S79 1994 005. 13'3-dc20 93-50758 CIP as AT&T Copyright © 1994 by AT&T Bell Labs. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. This book was typeset in Times Roman and Courier by the author. 1 23456789 10-MA-969594
Preface He who does not plow, must write. -MartinA. Hansen The ACM HOPL-2 conference on the History of Programming Languages asked me to write a paper on the history of C++. This seemed a reasonable idea and a bit of an honor, so I started writing. To get a more comprehensive and balanced view of C++'s growth, I asked a few friends from the early days of C++ for their recollections. That caused news of this project to travel through the grapevine. There, the story mutated, and one day I received a message from a friend asking where he could buy my new book on the design of C++. That email message is the real origin of this book. Traditional books about programming and programming languages explain what a language is and how to use it. However, many people are also curious about why a language is the way it is and how it came to be that way. This book answers these last two questions for C++. It explains how C++ evolved from its first design to the lan guage in use today. It describes the key problems, design aims, language ideas, and constraints that shaped C++, and how they changed over time. Naturally, C++ and the ideas about design and programming that shaped it didn't just mutate by themselves. What really evolved was the C++ users' understanding of their practical problems and of the tools needed to help solve them. Consequently, this book also traces the key problems tackled using C++ and the views of the people who tackled them in ways that influenced C++. C++ is still a young language. Some of the issues discussed here are yet unknown to many users. Many implications of decisions described here will not become obvi ous for years to come. This book presents my view of how C++ came about, what it is, and what it ought to be. I hope this will be of help to people trying to understand how best to use C++ and in the continuing evolution of C++.
iv Preface The emphasis is on the overall design goals, practical constraints, and people that shaped C++. The key design decisions relating to language features are discussed and put into their historical context. The evolution of C++ is traced from C with Classes through Release 1.0 and 2.0 to the current ANSIIISO standards work and the explo sion of use, tools, environments, and libraries. C++'s relationship to C and Simula is discussed in detail. C++' s relation ship to other languages is discussed briefly. The design of major language facilities such as classes, inheritance, abstract classes, overloading, memory management, tem plates, exception handling, run-time type information, and namespaces are discussed in some detail. interest, commercial activity, compilers, The primary aim of this book is to give C++ programmers a better idea of the background and fundamental concepts of their language and hopefully to inspire them to experiment with ways of using C++ that are new to them. This book can also be read by experienced programmers and students of programming languages and might help them decide whether using C++ might be worth their while. Acknowledgments I am very grateful to Steve Clamage, Tony Hansen, Lorraine Juhl, Peter Juhl, Brian Kernighan, Lee Knight, Doug Lea, Doug McIlroy, Barbara Moo, Jens Palsberg, Steve Rumsby, and Christopher Skelly for reading complete drafts of this book. Their con structive comments caused major changes to the contents and organization of this book. Steve Buroff, Martin Carroll, Sean Corfield, Tom Hagelskjrer, Rick Hollin beck, Dennis Mancl, and Stan Lippman helped by commenting on selected chapters. Also, thanks to Archie Lachner for asking for this book before I had thought of writ ing it. Naturally, lowe thanks to the many people who helped make C++. In a sense, this book is a tribute to them and some of their names can be found throughout the chap ters and in the index. Should I single out individuals, it must be Brian Kernighan, Andrew Koenig, Doug McIlroy, and Jonathan Shopiro, each of whom has been a steady source of help, encouragement, and ideas for more than a decade. Also, thanks to Kristen Nygaard and Dennis Ritchie as the designers of Simula and C from which the key ingredients of C++ were borrowed. Over the years, I have come to appreciate them not only as brilliant and practical language designers, but also as gentlemen and thoroughly likable individuals. Murray Hill, New Jersey Bjame Stroustrup
Contents iii iv v 1 1 2 4 4 5 7 17 19 19 22 23 Preface Contents Acknowledgments Notes to the Reader Introduction How to Read this Book C++ Timeline Focus on Use and Users Programming Languages References Part I: The Prehistory of C++ 1.1 Simula and Distributed Systems 1.2 C and Systems Programming 1.3 General Background
vi Contents C with Classes 2.1 The Birth of C with Classes 2.2 Feature overview 2.3 Classes 2.4 Run-Time Efficiency 2.5 The Linkage Model 2.6 Static Type Checking . 2.7 Why C? 2.8 Syntax Problems 2.9 Derived Classes 2.10 The Protection Model 2.11 Run-Time Guarantees 2.12 Minor Features 2.13 Features Considered, but not Provided 2.14 Work Environment The Birth of C++ 3.1 From C with Classes to C++ 3.2 Aims 3.3 Cfront 3.4 Language Features 3.5 Virtual Functions 3.6 Overloading 3.7 References 3.8 Constants 3.9 Memory Management 3.10 Type Checking 3.11 Minor Features 3.12 Relationship to Classic C 3.13 Tools for Language Design 3.14 The C++ Programming Language (1st edition) 3.15 The Whatis? Paper C++ Language Design Rules 4.1 Rules and Principles 4.2 General Rules 4.3 Design Support Rules 4.4 Language-Technical Rules 4.5 Low-Level Programming Support Rules 4.6 A Final Word 27 27 29 30 32 34 40 43 45 49 53 56 58 59 60 63 63 65 66 71 72 78 85 89 91 92 93 100 103 105 106 109 109 110 114 117 120 122
Contents vii Chronology 1985-1993 5.1 Introduction................................................................................. 5.2 Release 2.0 5.3 The Annotated Reference Manual 5.4 ANSI and ISO Standardization Standardization 6.1 What is a Standard? 6.2 How does the Committee Operate? 6.3 Clarifications 6.4 Extensions 6.5 Examples of Proposed Extensions Interest and Use 7.1 The Explosion in Interest and Use 7.2 Teaching and Learning C++ 7.3 Users and Applications 7.4 Commercial Competition Libraries 8.1 Introduction................................................................................. 8.2 C++ Library Design 8.3 Early Libraries 8.4 Other Libraries 8.5 A Standard Library Looking Ahead 9.1 Introduction.......................................................................... 9.2 Retrospective 9.3 Only a Bridge? 9.4 What Will Make C++ Much More Effective? 123 123 124 126 128 133 133 136 138 147 153 163 163 168 173 175 181 181 182 184 191 194 195 195 195 200 205
分享到:
收藏