7-PDF49-52_c++ programming

advertisement
Erich Gamma et al.: Design Patterns: Elements of Reusable Object-Oriented
Software.
Addison-Wesley.
Reading,
Massachusetts.
1994.
ISBN
0-201-63361-2.
34
Notes to the Reader
Chapter 1
Douglas Gregor et al.: Concepts: Linguistic Support for Generic Programming in C++. OOPSLA'06.
John L. Hennessy and David A. Patterson: Computer Architecture, Fifth Edi[Gamma,1995]
tion: A Quantitative Approach. Morgan Kaufmann. San Francisco, California. 2011. ISBN 978-0123838728.
Jean D. Ichbiah et al.: Rationale for the Design of the ADA
[Gregor,2006]
Programming
Language. SIGPLAN Notices. Vol. 14, No. 6. June 1979.
[Hennessy,2011]
Yogeesh H. Kamath, Ruth E. Smilan, and Jean G. Smith: Reaping
Benefits
with Object-Oriented Technology. AT&T Technical Journal. Vol. 72, No.
[Ichbiah,1979]
5.
September/October 1993.
[Kamath,1993]
Brian W. Kernighan and Dennis M. Ritchie: The C Programming Language.
Prentice Hall. Englewood Cliffs, New Jersey. 1978.
Brian W. Kernighan and Dennis M. Ritchie: The C Programming Language,
[Kernighan,1978]
Second Edition. Prentice-Hall. Englewood Cliffs, New Jersey. 1988. ISBN
0-13-110362-8.
[Kernighan,1988]
Donald E. Knuth: The Art of Computer Programming.
Addison-Wesley.
Reading, Massachusetts. 1968.
Andrew Koenig and Bjarne Stroustrup: C++: As close to C as possible - but
[Knuth,1968]
no closer. The C++ Report. Vol. 1, No. 7. July 1989.
A. R. Koenig and B. Stroustrup: Exception Handling for C++ (revised).
[Koenig,1989]
Proc USENIX C++ Conference. April 1990.
Joseph C. Kolecki: An Introduction to Tensors for Students of Physics
[Koenig,1990]
and
Engineering. NASA/TM-2002-211716.
[Kolecki,2002]
Angelika Langer and Klaus Kreft: Standard C++ IOStreams and Locales:
Advanced Programmer's Guide and Reference.
Addison-Wesley. 2000.
[Langer,2000]
ISBN 978-0201183955.
Paul E. McKenney: Is Parallel Programming Hard, And, If So, What
Can
[McKenney]
You Do About It? kernel.org. Corvallis, Oregon. 2012.
http://kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html.
John Maddock: Boost.Regex. www.boost.org. 2009.
[Maddock,2009]
George Orwell: 1984. Secker and Warburg. London. 1949.
[Orwell,1949]
Larry C. Paulson: ML for the Working Programmer. Cambridge
[Paulson,1996]
University
Press. Cambridge. 1996. ISBN 0-521-56543-X.
[Pirkelbauer,2009]
P. Pirkelbauer, Y. Solodkyy, and B. Stroustrup: Design and Evaluation of
C++ Open Multi-Methods. Science of Computer Programming. Elsevier
Journal. June 2009. doi:10.1016/j.scico.2009.06.002.
[Richards,1980]
Martin Richards and Colin Whitby-Strevens: BCPL - The Language and Its
Compiler.
Cambridge
University
Press.
Cambridge.
1980.
ISBN
[Root,1995]
0-521-21965-5.
ROOT: A Data Analysis Framework. root.cern.ch. It seems appropriate
to
represent a tool from CERN, the birthplace of the World Wide Web,
Section 1.6
[Rozier,1988]
[Siek,2000]
[Solodkyy,2012]
[Stepanov,1994]
[Stewart,1998]
[Stroustrup,1982]
[Stroustrup,1984]
[Stroustrup,1985]
[Stroustrup,1986]
[Stroustrup,1987]
[Stroustrup,1987b]
[Stroustrup,1988]
[Stroustrup,1991]
[Stroustrup,1993]
[Stroustrup,1994]
[Stroustrup,1997]
[Stroustrup,2002]
[Stroustrup,2007]
Web address.
M. Rozier et al.: CHORUS Distributed Operating Systems. Computing Systems. Vol. 1, No. 4. Fall 1988.
References
35
Jeremy G. Siek and Andrew Lumsdaine: Concept checking:
Binding parametric polymorphism in C++. Proc. First Workshop on C++ Template
Programming. Erfurt, Germany. 2000.
Y. Solodkyy, G. Dos Reis, and B. Stroustrup: Open and Efficient Type Switch
for C++. Proc. OOPSLA'12.
Alexander Stepanov and Meng Lee: The Standard Template Library. HP
Labs Technical Report HPL-94-34 (R. 1). 1994.
G. W. Stewart: Matrix Algorithms, Volume I. Basic Decompositions. SIAM.
Philadelphia, Pennsylvania. 1998.
B. Stroustrup: Classes: An Abstract Data Type Facility for the C
Language.
Sigplan Notices. January 1982.
The first public description of ''C with
Classes.''
B. Stroustrup: Operator Overloading in C++. Proc. IFIP WG2.4 Conference on System Implementation Languages: Experience &
Assessment.
September 1984.
B. Stroustrup: An Extensible I/O Facility for C++.
Proc. Summer 1985
USENIX Conference.
B. Stroustrup: The C++ Programming Language. Addison-Wesley. Reading, Massachusetts. 1986. ISBN 0-201-12078-X.
B. Stroustrup: Multiple Inheritance for C++. Proc. EUUG Spring Conference. May 1987.
B. Stroustrup and J. Shopiro: A Set of C Classes for Co-Routine Style
Programming.
Proc. USENIX C++ Conference.
Santa Fe, New
Mexico.
November 1987.
B. Stroustrup: Parameterized Types for C++. Proc. USENIX C++ Conference, Denver. 1988.
B. Stroustrup: The C++ Programming Language (Second Edition). Addison-Wesley. Reading, Massachusetts. 1991. ISBN 0-201-53992-6.
B. Stroustrup: A History of C++: 1979-1991. Proc. ACM History of
Programming Languages conference (HOPL-2). ACM Sigplan Notices. Vol 28,
No 3. 1993.
B. Stroustrup: The Design and Evolution of C++. Addison-Wesley.
Reading, Mass. 1994. ISBN 0-201-54330-3.
B. Stroustrup: The C++ Programming Language, Third Edition. AddisonWesley. Reading, Massachusetts. 1997. ISBN 0-201-88954-4. Hardcover
(''Special'') Edition. 2000. ISBN 0-201-70073-5.
B. Stroustrup: C and C++: Siblings, C and C++: A Case for Compatibility,
and C and C++: Case Studies in Compatibility. The C/C++ Users
Journal.
July-September 2002. www.stroustrup.com/papers.html.
B. Stroustrup: Evolving a language in and for the real world:
C++
1991-2006. ACM HOPL-III. June 2007.
36
Notes to the Reader
[Stroustrup,2008]
[Stroustrup,2010a]
[Stroustrup,2010b]
[Stroustrup,2012a]
[Stroustrup,2012b]
[Sutton,2011]
[Tanenbaum,2007]
[Tsafrir,2009]
[Unicode,1996]
[UNIX,1985]
[Vandevoorde,2002]
Complete
[Veldhuizen,1995]
[Veldhuizen,2003]
[Vitter,1985]
[WG21]
[Williams,2012]
[Wilson,1996]
[Wood,1999]
[Woodward,1974]
Chapter 1
B. Stroustrup: Programming - Principles and Practice Using C++. Addison-Wesley. 2009. ISBN 0-321-54372-6.
B. Stroustrup: The C++11 FAQ. www.stroustrup.com/C++11FAQ.html.
B. Stroustrup: The C++0x ''Remove Concepts'' Decision. Dr. Dobb's Journal. July 2009.
B. Stroustrup and A. Sutton: A Concept Design for the STL. WG21 Technical Report N3351==12-0041. January 2012.
B. Stroustrup: Software Development for Infrastructure. Computer. January
2012. doi:10.1109/MC.2011.353.
A. Sutton and B. Stroustrup: Design of Concept Libraries for C++. Proc.
SLE 2011 (International Conference on Software Language Engineering).
July 2011.
Andrew S. Tanenbaum: Modern Operating Systems, Third Edition. Prentice
Hall. Upper Saddle River, New Jersey. 2007. ISBN 0-13-600663-9.
Dan Tsafrir et al.: Minimizing Dependencies within Generic Classes for
Faster and Smaller Programs. ACM OOPSLA'09. October 2009.
The Unicode Consortium: The Unicode Standard, Version 2.0.
AddisonWesley. Reading, Massachusetts. 1996. ISBN 0-201-48345-9.
UNIX Time-Sharing System: Programmer's Manual.
Research Version,
Tenth Edition. AT&T Bell Laboratories, Murray Hill, New Jersey. February
1985.
David Vandevoorde and Nicolai M. Josuttis: C++ Templates: The
Guide.
Addison-Wesley.
2002.
ISBN 0-201-73484-2.
Todd Veldhuizen:
Expression
Templates.
The C++ Report. June 1995.
Todd L. Veldhuizen: C++ Templates are Turing Complete. Indiana
University Computer Science Technical Report. 2003.
Jefferey Scott Vitter: Random Sampling with a Reservoir. ACM Transactions on Mathematical Software, Vol. 11, No. 1. 1985.
ISO SC22/WG21 The C++ Programming Language Standards Committee:
Document Archive. www.open-std.org/jtc1/sc22/wg21.
Anthony Williams: C++ Concurrency in Action - Practical Multithreading.
Manning Publications Co. ISBN 978-1933988771.
Gregory V. Wilson and Paul Lu (editors): Parallel Programming Using C++.
The MIT Press. Cambridge, Mass. 1996. ISBN 0-262-73118-5.
Alistair Wood: Introduction to Numerical Analysis. Addison-Wesley. Reading, Massachusetts. 1999. ISBN 0-201-34291-X.
P. M. Woodward and S. G. Bond: Algol 68-R Users Guide. Her
Majesty's
Stationery Office. London. 1974.
2
A Tour of C++: The Basics
The first thing we do, let's
kill all the language lawyers.
- Henry VI, Part II
•
•
•
•
•
•
2.1
Introduction
The Basics
Hello, World!; Types, Variables, and Arithmetic; Constants; Tests and Loops; Pointers,
Arrays, and Loops
User-Defined Types
Structures; Classes; Enumerations
Modularity
Separate Compilation; Namespaces; Error Handling
Postscript
Advice
Introduction
The aim of this chapter and the next three is to give you an idea of what C++ is, without going into
a lot of details. This chapter informally presents the notation of C++, C++'s model of memory and
computation, and the basic mechanisms for organizing code into a program. These are the language facilities supporting the styles most often seen in C and sometimes called procedural programming. Chapter 3 follows up by presenting C++'s abstraction mechanisms. Chapter 4 and
Chapter 5 give examples of standard-library facilities.
The assumption is that you have programmed before. If not, please consider reading a textbook, such as Programming: Principles and Practice Using C++ [Stroustrup,2009], before continuing here. Even if you have programmed before, the language you used or the applications you
wrote may be very different from the style of C++ presented here. If you find this ''lightning tour''
confusing, skip to the more systematic presentation starting in Chapter 6.
Download