You are on page 1of 53

Programming Principles and Practice

Using C Third Edition Bjarne Stroustrup


Visit to download the full and correct content document:
https://textbookfull.com/product/programming-principles-and-practice-using-c-third-edi
tion-bjarne-stroustrup/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Programming: Principles and Practice Using C++ , Second


Edition Stroustrup

https://textbookfull.com/product/programming-principles-and-
practice-using-c-second-edition-stroustrup/

Programming Principles and Practice Using C 3rd


Edition Stroustrup

https://textbookfull.com/product/programming-principles-and-
practice-using-c-3rd-edition-stroustrup/

Computer Graphics Programming in OpenGL Using C++,


Third Edition Gordon Phd

https://textbookfull.com/product/computer-graphics-programming-
in-opengl-using-c-third-edition-gordon-phd/

A Tour of C++ Stroustrup

https://textbookfull.com/product/a-tour-of-c-stroustrup/
A Tour of C++ Stroustrup

https://textbookfull.com/product/a-tour-of-c-stroustrup-2/

Pavement Engineering: Principles and Practice, Third


Edition El-Korchi

https://textbookfull.com/product/pavement-engineering-principles-
and-practice-third-edition-el-korchi/

A Tour of C 3rd Edition Stroustrup B.

https://textbookfull.com/product/a-tour-of-c-3rd-edition-
stroustrup-b/

Tour of C A C In Depth Series 3rd Edition Stroustrup

https://textbookfull.com/product/tour-of-c-a-c-in-depth-
series-3rd-edition-stroustrup/

Post Tensioned Concrete Principles and Practice Third


Edition K. Dirk Bondy

https://textbookfull.com/product/post-tensioned-concrete-
principles-and-practice-third-edition-k-dirk-bondy/
About This eBook
ePUB is an open, industry-standard format for eBooks. However,
support of ePUB and its many features varies across reading devices
and applications. Use your device or app settings to customize the
presentation to your liking. Settings that you can customize often
include font, font size, single or double column, landscape or portrait
mode, and figures that you can click or tap to enlarge. For additional
information about the settings and features on your reading device
or app, visit the device manufacturer’s Web site.
Many titles include programming code or configuration examples.
To optimize the presentation of these elements, view the eBook in
single-column, landscape mode and adjust the font size to the
smallest setting. In addition to presenting code and configurations in
the reflowable text format, we have included images of the code
that mimic the presentation found in the print book; therefore,
where the reflowable format may compromise the presentation of
the code listing, you will see a “Click here to view code image” link.
Click the link to view the print-fidelity code image. To return to the
previous page viewed, click the Back button on your device or app.
Programming: Principles and
Practice Using C++

Third Edition

Bjarne Stroustrup

Hoboken, New Jersey


Cover photo by Photowood Inc./Corbis.
Author photo courtesy of Bjarne Stroustrup.
Page 294: “Promenade a Skagen” by Peder Severin Kroyer.
Page 308: Photo of NASA’s Ingenuity Mars Helicopter, The National
Aeronautics and Space Administration (NASA).
Page 354: Photo of Hurricane Rita as seen from space, The National
Oceanic and Atmospheric Administration (NOAA).

Many of the designations used by manufacturers and sellers to


distinguish their products are claimed as trademarks. Where those
designations appear in this book, and the publisher was aware of a
trademark claim, the designations have been printed with initial
capital letters or in all capitals.

The author and publisher have taken care in the preparation of this
book, but make no expressed or implied warranty of any kind and
assume no responsibility for errors or omissions. No liability is
assumed for incidental or consequential damages in connection with
or arising out of the use of the information or programs contained
herein.

For information about buying this title in bulk quantities, or for


special sales opportunities (which may include electronic versions;
custom cover designs; and content particular to your business,
training goals, marketing focus, or branding interests), please
contact our corporate sales department at
corpsales@pearsoned.com or (800) 382-3419.

For government sales inquiries, please contact


governmentsales@pearsoned.com.
For questions about sales outside the U.S., please contact
intlcs@pearson.com.

Visit us on the Web: informit.com/aw

Library of Congress Control Number: 2024932369

Copyright 2024 by Pearson Education, Inc.

All rights reserved. This publication is protected by copyright, and


permission must be obtained from the publisher prior to any
prohibited reproduction, storage in a retrieval system, or
transmission in any form or by any means, electronic, mechanical,
photocopying, recording, or likewise. For information regarding
permissions, request forms and the appropriate contacts within the
Pearson Education Global Rights & Permissions Department, please
visit www.pearson.com/permissions.

This book was typeset in Times and Helvetica by the author.

ISBN-13: 978-0-13-830868-1
ISBN-10: 0-13-83086-3
First printing, May 2024
$PrintCode
Contents

Preface

0 Notes to the Reader


0.1 The structure of this book
0.2 A philosophy of teaching and learning
0.3 ISO standard C++
0.4 PPP support
0.5 Author biography
0.6 Bibliography

Part I: The Basics

1 Hello, World!
1.1 Programs
1.2 The classic first program
1.3 Compilation
1.4 Linking
1.5 Programming environments

2 Objects, Types, and Values


2.1 Input
2.2 Variables
2.3 Input and type
2.4 Operations and operators
2.5 Assignment and initialization
2.6 Names
2.7 Types and objects
2.8 Type safety
2.9 Conversions
2.10 Type deduction: auto

3 Computation
3.1 Computation
3.2 Objectives and tools
3.3 Expressions
3.4 Statements
3.5 Functions
3.6 vector
3.7 Language features

4 Errors!
4.1 Introduction
4.2 Sources of errors
4.3 Compile-time errors
4.4 Link-time errors
4.5 Run-time errors
4.6 Exceptions
4.7 Avoiding and finding errors

5 Writing a Program
5.1 A problem
5.2 Thinking about the problem
5.3 Back to the calculator!
5.4 Back to the drawing board
5.5 Turning a grammar into code
5.6 Trying the first version
5.7 Trying the second version
5.8 Token streams
5.9 Program structure

6 Completing a Program
6.1 Introduction
6.2 Input and output
6.3 Error handling
6.4 Negative numbers
6.5 Remainder: %
6.6 Cleaning up the code
6.7 Recovering from errors
6.8 Variables

7 Technicalities: Functions, etc.


7.1 Technicalities
7.2 Declarations and definitions
7.3 Scope
7.4 Function call and return
7.5 Order of evaluation
7.6 Namespaces
7.7 Modules and headers

8 Technicalities: Classes, etc.


8.1 User-defined types
8.2 Classes and members
8.3 Interface and implementation
8.4 Evolving a class: Date
8.5 Enumerations
8.6 Operator overloading
8.7 Class interfaces

Part II: Input and Output

9 Input and Output Streams


9.1 Input and output
9.2 The I/O stream model
9.3 Files
9.4 I/O error handling
9.5 Reading a single value
9.6 User-defined output operators
9.7 User-defined input operators
9.8 A standard input loop
9.9 Reading a structured file
9.10 Formatting
9.11 String streams

10 A Display Model
10.1 Why graphics?
10.2 A display model
10.3 A first example
10.4 Using a GUI library
10.5 Coordinates
10.6 Shapes
10.7 Using Shape primitives
10.8 Getting the first example to run

11 Graphics Classes
11.1 Overview of graphics classes
11.2 Point and Line
11.3 Lines
11.4 Color
11.5 Line_style
11.6 Polylines
11.7 Closed shapes
11.8 Text
11.9 Mark
11.10 Image

12 Class Design
12.1 Design principles
12.2 Shape
12.3 Base and derived classes
12.4 Other Shape functions
12.5 Benefits of object-oriented programming

13 Graphing Functions and Data


13.1 Introduction
13.2 Graphing simple functions
13.3 Function
13.4 Axis
13.5 Approximation
13.6 Graphing data

14 Graphical User Interfaces


14.1 User-interface alternatives
14.2 The “Next” button
14.3 A simple window
14.4 Button and other Widgets
14.5 An example: drawing lines
14.6 Simple animation
14.7 Debugging GUI code

Part III: Data and Algorithms

15 Vector and Free Store


15.1 Introduction
15.2 vector basics
15.3 Memory, addresses, and pointers
15.4 Free store and pointers
15.5 Destructors
15.6 Access to elements
15.7 An example: lists
15.8 The this pointer

16 Arrays, Pointers, and References


16.1 Arrays
16.2 Pointers and references
16.3 C-style strings
16.4 Alternatives to pointer use
16.5 An example: palindromes

17 Essential Operations
17.1 Introduction
17.2 Access to elements
17.3 List initialization
17.4 Copying and moving
17.5 Essential operations
17.6 Other useful operations
17.7 Remaining Vector problems
17.8 Changing size
17.9 Our Vector so far
18 Templates and Exceptions
18.1 Templates
18.2 Generalizing Vector
18.3 Range checking and exceptions
18.4 Resources and exceptions
18.5 Resource-management pointers

19 Containers and Iterators


19.1 Storing and processing data
19.2 Sequences and iterators
19.3 Linked lists
19.4 Generalizing Vector yet again
19.5 An example: a simple text editor
19.6 vector, list, and string

20 Maps and Sets


20.1 Associative containers
20.2 map
20.3 unordered_map
20.4 Timing
20.5 set
20.6 Container overview
20.7 Ranges and iterators

21 Algorithms
21.1 Standard-library algorithms
21.2 Function objects
21.3 Numerical algorithms
21.4 Copying
21.5 Sorting and searching
Index
Preface

Damn the
torpedoes!
Full speed ahead.
– Admiral
Farragut

Programming is the art of expressing solutions to problems so that a


computer can execute those solutions. Much of the effort in
programming is spent finding and refining solutions. Often, a
problem is only fully understood through the process of
programming a solution for it.
This book is for someone who has never programmed before but
is willing to work hard to learn. It helps you understand the
principles and acquire the practical skills of programming using the
C++ programming language. It can also be used by someone with
some programming knowledge who wants a more thorough
grounding in programming principles and contemporary C++.
Why would you want to program? Our civilization runs on
software. Without understanding software, you are reduced to
believing in “magic” and will be locked out of many of the most
interesting, profitable, and socially useful technical fields of work.
When I talk about programming, I think of the whole spectrum of
computer programs from personal computer applications with GUIs
(graphical user interfaces), through engineering calculations and
embedded systems control applications (such as digital cameras,
cars, and cell phones), to text manipulation applications as found in
many humanities and business applications. Like mathematics,
programming – when done well – is a valuable intellectual exercise
that sharpens our ability to think. However, thanks to feedback from
the computer, programming is more concrete than most forms of
math and therefore accessible to more people. It is a way to reach
out and change the world – ideally for the better. Finally,
programming can be great fun.
There are many kinds of programming. This book aims to serve
those who want to write nontrivial programs for the use of others
and to do so responsibly, providing a decent level of system quality.
That is, I assume that you want to achieve a level of
professionalism. Consequently, I chose the topics for this book to
cover what is needed to get started with real-world programming,
not just what is easy to teach and learn. If you need a technique to
get basic work done right, I describe it, demonstrate concepts and
language facilities needed to support the technique, and provide
exercises for it. If you just want to understand toy programs or write
programs that just call code provided by others, you can get along
with far less than I present. In such cases, you will probably also be
better served by a language that’s simpler than C++. On the other
hand, I won’t waste your time with material of marginal practical
importance. If an idea is explained here, it’s because you’ll almost
certainly need it.
Programming is learned by writing programs. In this,
programming is similar to other endeavors with a practical
component. You cannot learn to swim, to play a musical instrument,
or to drive a car just from reading a book – you must practice. Nor
can you become a good programmer without reading and writing
lots of code. This book focuses on code examples closely tied to
explanatory text and diagrams. You need those to understand the
ideals, concepts, and principles of programming and to master the
language constructs used to express them. That’s essential, but by
itself, it will not give you the practical skills of programming. For
that, you need to do the exercises and get used to the tools for
writing, compiling, and running programs. You need to make your
own mistakes and learn to correct them. There is no substitute for
writing code. Besides, that’s where the fun is!
There is more to programming – much more – than following a
few rules and reading the manual. This book is not focused on “the
syntax of C++.” C++ is used to illustrate fundamental concepts.
Understanding the fundamental ideals, principles, and techniques is
the essence of a good programmer. Also, “the fundamentals” are
what last: they will still be essential long after today’s programming
languages and tools have evolved or been replaced.
Code can be beautiful as well as useful. This book is written to
help you to understand what it means for code to be beautiful, to
help you to master the principles of creating such code, and to build
up the practical skills to create it. Good luck with programming!

Previous Editions
The third edition of Programming: Principles and Practice Using C++
is about half the size of the second edition. Students having to carry
the book will appreciate the lighter weight. The reason for the
reduced size is simply that more information about C++ and its
standard library is available on the Web. The essence of the book
that is generally used in a course in programming is in this third
edition (“PPP3”), updated to C++20 plus a bit of C++23. The fourth
part of the previous edition (“PPP2”) was designed to provide extra
information for students to look up when needed and is available on
the Web:

Chapter 1: Computers, People, and Programming


Chapter 11: Customizing Input and Output
Chapter 22: Ideas and History
Chapter 23 Text Manipulation
Chapter 24: Numerics
Chapter 25: Embedded Systems Programming
Chapter 26: Testing
Chapter 27: The C Programming Language
Glossary

Where I felt it useful to reference these chapters, the references


look like this: PPP2.Ch22 or PPP2.§27.1.

Acknowledgments
Special thanks to the people who reviewed drafts of this book and
suggested many improvements: Clovis L. Tondo, Jose Daniel Garcia
Sanchez, J.C. van Winkel, and Ville Voutilainen. Also, Ville Voutilainen
did the non-trivial mapping of the GUI/Graphics interface library to
Qt, making it portable to an amazing range of systems.
Also, thanks to the many people who contributed to the first and
second editions of this book. Many of their comments are reflected
in this third edition.
0

Notes to the Reader

eiπ + 1
– Leonhard Euler

This chapter is a grab bag of information; it aims to give you an idea of


what to expect from the rest of the book. Please skim through it and read
what you find interesting. Before writing any code, read “PPP support”
(§0.4). A teacher will find most parts immediately useful. If you are
reading this book as a novice, please don’t try to understand everything.
You may want to return and reread this chapter once you feel comfortable
writing and executing small programs.

§0.1 The structure of this book


General approach; Drills, exercises, etc.; What comes after this book?
§0.2 A philosophy of teaching and learning
A note to students; A note to teachers
§0.3 ISO standard C++
Portability; Guarantees; A brief history of C++
§0.4 PPP support
Web resources
§0.5 Author biography
§0.6 Bibliography

0.1 The structure of this book


This book consists of three parts:

Part I (Chapter 1 to Chapter 8) presents the fundamental concepts and


techniques of programming together with the C++ language and library
facilities needed to get started writing code. This includes the type system,
arithmetic operations, control structures, error handling, and the design,
implementation, and use of functions and user-defined types.
Part II (Chapter 9 to Chapter 14) first describes how to get numeric and text
data from the keyboard and from files, and how to produce corresponding
output to the screen and to files. Then, we show how to present numeric data,
text, and geometric shapes as graphical output, and how to get input into a
program from a graphical user interface (GUI). As part of that, we introduce
the fundamental principles and techniques of object-oriented programming.
Part III (Chapter 15 to Chapter 21) focuses on the C++ standard library’s
containers and algorithms framework (often referred to as the STL). We show
how containers (such as vector, list, and map) are implemented and used. In
doing so, we introduce low-level facilities such as pointers, arrays, and dynamic
memory. We also show how to handle errors using exceptions and how to
parameterize our classes and functions using templates. As part of that, we
introduce the fundamental principles and techniques of generic programming.
We also demonstrate the design and use of standard-library algorithms (such
as sort, find, and inner_product).

The order of topics is determined by programming techniques, rather than


programming language features.

CC
To ease review and to help you if you miss a key point during a first reading
where you have yet to discover which kind of information is crucial, we place three
kinds of “alert markers” in the margin:

CC: concepts and techniques (this paragraph is an example of that)


AA: advice
XX: warning
The use of CC, AA, and XX, rather than a single token in different colors, is to help
where colors are not easy to distinguish.

0.1.1 General approach


In this book, we address you directly. That is simpler and clearer than the
conventional “professional” indirect form of address, as found in most scientific
papers. By “you” we mean “you, the reader,” and by “we” we mean “you, the
author, and teachers,” working together through a problem, as we might have done
had we been in the same room. I use "I" when I refer to my own work or personal
opinions.

AA
This book is designed to be read chapter by chapter from the beginning to the
end. Often, you’ll want to go back to look at something a second or a third time. In
fact, that’s the only sensible approach, as you’ll always dash past some details that
you don’t yet see the point in. In such cases, you’ll eventually go back again.
Despite the index and the cross-references, this is not a book that you can open to
any page and start reading with any expectation of success. Each section and each
chapter assume understanding of what came before.
Each chapter is a reasonably self-contained unit, meant to be read in “one
sitting” (logically, if not always feasible on a student’s tight schedule). That’s one
major criterion for separating the text into chapters. Other criteria include that a
chapter is a suitable unit for drills and exercises and that each chapter presents
some specific concept, idea, or technique. This plurality of criteria has left a few
chapters uncomfortably long, so please don’t take “in one sitting” too literally. In
particular, once you have thought about the review questions, done the drill, and
worked on a few exercises, you’ll often find that you have to go back to reread a
few sections.
A common praise for a textbook is “It answered all my questions just as I
thought of them!” That’s an ideal for minor technical questions, and early readers
have observed the phenomenon with this book. However, that cannot be the whole
ideal. We raise questions that a novice would probably not think of. We aim to ask
and answer questions that you need to consider when writing quality software for
the use of others. Learning to ask the right (often hard) questions is an essential
part of learning to think as a programmer. Asking only the easy and obvious
questions would make you feel good, but it wouldn’t help make you a programmer.
We try to respect your intelligence and to be considerate about your time. In our
presentation, we aim for professionalism rather than cuteness, and we’d rather
understate a point than hype it. We try not to exaggerate the importance of a
programming technique or a language feature, but please don’t underestimate a
simple statement like “This is often useful.” If we quietly emphasize that something
is important, we mean that you’ll sooner or later waste days if you don’t master it.
Our use of humor is more limited than we would have preferred, but experience
shows that people’s ideas of what is funny differ dramatically and that a failed
attempt at humor can be confusing.

CC
We do not pretend that our ideas or the tools offered are perfect. No tool, library,
language, or technique is “the solution” to all of the many challenges facing a
programmer. At best, a language can help you to develop and express your solution.
We try hard to avoid “white lies”; that is, we refrain from oversimplified
explanations that are clear and easy to understand, but not true in the context of
real languages and real problems.

0.1.2 Drills, exercises, etc


AA
Programming is not just an intellectual activity, so writing programs is necessary to
master programming skills. We provide three levels of programming practice:

Drills: A drill is a very simple exercise devised to develop practical, almost


mechanical skills. A drill usually consists of a sequence of modifications of a
single program. You should do every drill. A drill is not asking for deep
understanding, cleverness, or initiative. We consider the drills part of the basic
fabric of the book. If you haven’t done the drills, you have not “done” the book.
Exercises: Some exercises are trivial, and others are very hard, but most are
intended to leave some scope for initiative and imagination. If you are serious,
you’ll do quite a few exercises. At least do enough to know which are difficult
for you. Then do a few more of those. That’s how you’ll learn the most. The
exercises are meant to be manageable without exceptional cleverness, rather
than to be tricky puzzles. However, we hope that we have provided exercises
that are hard enough to challenge anybody and enough exercises to exhaust
even the best student’s available time. We do not expect you to do them all,
but feel free to try.
Try this: Some people like to put the book aside and try some examples before
reading to the end of a chapter; others prefer to read ahead to the end before
trying to get code to run. To support readers with the former preference, we
provide simple suggestions for practical work labeled Try this at natural breaks
in the text. A Try this is generally in the nature of a drill but focused narrowly
on the topic that precedes it. If you pass a Try this without trying it out –
maybe because you are not near a computer or you find the text riveting – do
return to it when you do the chapter drill; a Try this either complements the
chapter drill or is a part of it.

In addition, at the end of each chapter we offer some help to solidify what’s
learned:

Review: At the end of each chapter, you’ll find a set of review questions. They
are intended to point you to the key ideas explained in the chapter. One way to
look at the review questions is as a complement to the exercises: the exercises
focus on the practical aspects of programming, whereas the review questions
try to help you articulate the ideas and concepts. In that, they resemble good
interview questions.
Terms: A section at the end of each chapter presents the basic vocabulary of
programming and of C++. If you want to understand what people say about
programming topics and to articulate your own ideas, you should know what
each term means.
Postscript: A paragraph intended to provide some perspective for the material
presented.

In addition, we recommend that you take part in a small project (and more if time
allows for it). A project is intended to produce a complete useful program. Ideally, a
project is done by a small group of people (e.g., three people) working together
(e.g., while progressing through the later chapters of the book). Most people find
such projects the most fun and that they tie everything together.

CC
Learning involves repetition. Our ideal is to make every important point at least
twice and to reinforce it with exercises.

0.1.3 What comes after this book?


AA
At the end of this book, will you be an expert at programming and at C++? Of
course not! When done well, programming is a subtle, deep, and highly skilled art
building on a variety of technical skills. You should no more expect to become an
expert at programming in four months than you should expect to become an expert
in biology, in math, in a natural language (such as Chinese, English, or Danish), or
at playing the violin in four months – or in half a year, or a year. What you should
hope for, and what you can expect if you approach this book seriously, is to have a
really good start that allows you to write relatively simple useful programs, to be
able to read more complex programs, and to have a good conceptual and practical
background for further work.
The best follow-up to this initial course is to work on a project developing code
to be used by someone else; preferably guided by an experienced developer. After
that, or (even better) in parallel with a project, read either a professional-level
general textbook, a more specialized book relating to the needs of your project, or a
textbook focusing on a particular aspect of C++ (such as algorithms, graphics,
scientific computation, finance, or games); see §0.6.

AA
Eventually, you should learn another programming language. We don’t consider
it possible to be a professional in the realm of software – even if you are not
primarily a programmer – without knowing more than one language. Why? No large
program is written in a single language. Also, different languages typically differ in
the way code is thought about and programs are constructed. Design techniques,
availability of libraries, and the way programs are built differ, sometimes
dramatically. Even when the syntaxes of two languages are similar, the similarity is
typically only skin deep. Performance, detection of errors, and constraints on what
can be expressed typically differ. This is similar to the ways natural languages and
cultures differ. Knowing only a single language and a single culture implies the
danger of thinking that “the way we do things” is the only way or the only good
way. That way opportunities are missed, and sub-optimal programs are produced.
One of the best ways to avoid such problems is to know several languages
(programming languages and natural languages).

0.2 A philosophy of teaching and learning


What are we trying to help you learn? And how are we approaching the process of
teaching? We try to present the minimal concepts, techniques, and tools for you to
do effective practical programs, including

Program organization
Debugging and testing
Class design
Computation
Function and algorithm design
Graphics (two-dimensional only)
Graphical user interfaces (GUIs)
Files and stream input and output (I/O)
Memory management
Design and programming ideals
The C++ standard library
Software development strategies

To keep the book lighter than the small laptop on which it is written, some
supplementary topics from the second edition are placed on the Web (§0.4.1):

Computers, People, and Programming (PPP2.Ch1)


Ideals and History (PPP2.Ch22)
Text manipulation (incl. Regular expression matching) (PPP2.Ch23)
Numerics (PPP2.Ch24)
Embedded systems programming (PPP2.Ch25)
C-language programming techniques (PPP2.Ch27)

Working our way through the chapters, we cover the programming techniques
called procedural programming (as with the C programming language), data
abstraction, object-oriented programming, and generic programming. The main
topic of this book is programming, that is, the ideals, techniques, and tools of
expressing ideas in code. The C++ programming language is our main tool, so we
describe many of C++’s facilities in some detail. But please remember that C++ is
just a tool, rather than the main topic of this book. This is “programming using
C++,” not “C++ with a bit of programming theory.”
Each topic we address serves at least two purposes: it presents a technique,
concept, or principle and also a practical language or library feature. For example,
we use the interface to a two-dimensional graphics system to illustrate the use of
classes and inheritance. This allows us to be economical with space (and your time)
and also to emphasize that programming is more than simply slinging code together
to get a result as quickly as possible. The C++ standard library is a major source of
such “double duty” examples – many even do triple duty. For example, we introduce
the standard-library vector, use it to illustrate widely useful design techniques, and
show many of the programming techniques used to implement it. One of our aims
is to show you how major library facilities are implemented and how they map to
hardware. We insist that craftsmen must understand their tools, not just consider
them “magical.”
Some topics will be of greater interest to some programmers than to others.
However, we encourage you not to prejudge your needs (how would you know what
you’ll need in the future?) and at least look at every chapter. If you read this book
as part of a course, your teacher will guide your selection.
CC
We characterize our approach as “depth-first.” It is also “concrete-first” and
“concept-based.” First, we quickly (well, relatively quickly, Chapter 1 to Chapter 9)
assemble a set of skills needed for writing small practical programs. In doing so, we
present a lot of tools and techniques in minimal detail. We focus on simple concrete
code examples because people grasp the concrete faster than the abstract. That’s
simply the way most humans learn. At this initial stage, you should not expect to
understand every little detail. In particular, you’ll find that trying something slightly
different from what just worked can have “mysterious” effects. Do try, though!
Please do the drills and exercises we provide. Just remember that early on you just
don’t have the concepts and skills to accurately estimate what’s simple and what’s
complicated; expect surprises and learn from them.

AA
We move fast in this initial phase – we want to get you to the point where you
can write interesting programs as fast as possible. Someone will argue, “We must
move slowly and carefully; we must walk before we can run!” But have you ever
watched a baby learning to walk? Babies really do run by themselves before they
learn the finer skills of slow, controlled walking. Similarly, you will dash ahead,
occasionally stumbling, to get a feel of programming before slowing down to gain
the necessary finer control and understanding. You must run before you can walk!

XX
It is essential that you don’t get stuck in an attempt to learn “everything” about
some language detail or technique. For example, you could memorize all of C++’s
built-in types and all the rules for their use. Of course you could, and doing so
might make you feel knowledgeable. However, it would not make you a
programmer. Skipping details will get you “burned” occasionally for lack of
knowledge, but it is the fastest way to gain the perspective needed to write good
programs. Note that our approach is essentially the one used by children learning
their native language and also the most effective approach used to learn a foreign
language. We encourage you to seek help from teachers, friends, colleagues,
Mentors, etc. on the inevitable occasions when you are stuck. Be assured that
nothing in these early chapters is fundamentally difficult. However, much will be
unfamiliar and might therefore feel difficult at first.
Later, we build on your initial skills to broaden your base of knowledge. We use
examples and exercises to solidify your understanding, and to provide a conceptual
base for programming.

AA
We place a heavy emphasis on ideals and reasons. You need ideals to guide you
when you look for practical solutions – to know when a solution is good and
principled. You need to understand the reasons behind those ideals to understand
why they should be your ideals, why aiming for them will help you and the users of
your code. Nobody should be satisfied with “because that’s the way it is” as an
explanation. More importantly, an understanding of ideals and reasons allows you to
generalize from what you know to new situations and to combine ideas and tools in
novel ways to address new problems. Knowing “why” is an essential part of
acquiring programming skills. Conversely, just memorizing lots of poorly understood
rules is limiting, a source of errors, and a massive waste of time. We consider your
time precious and try not to waste it.
Many C++ language-technical details are banished to other sources, mostly on
the Web (§0.4.1). We assume that you have the initiative to search out information
when needed. Use the index and the table of contents. Don’t forget the online help
facilities of your compiler. Remember, though, to consider every Web resource
highly suspect until you have reason to believe better of it. Many an authoritative-
looking Web site is put up by a programming novice or someone with something to
sell. Others are simply outdated. We provide a collection of links and information on
our support Web site: www.stroustrup.com/programming.xhtml.
Please don’t be too impatient for “realistic” examples. Our ideal example is the
shortest and simplest code that directly illustrates a language facility, a concept, or
a technique. Most real-world examples are far messier than ours, yet do not consist
of more than a combination of what we demonstrate. Successful commercial
programs with hundreds of thousands of lines of code are based on techniques that
we illustrate in a dozen 50-line programs. The fastest way to understand real-world
code is through a good understanding of the fundamentals.
We do not use “cute examples involving cuddly animals” to illustrate our points.
We assume that you aim to write real programs to be used by real people, so every
example that is not presented as specifically language-technical is taken from a
real-world use. Our basic tone is that of professionals addressing (future)
professionals.
C++ rests on two pillars:

Efficient direct access to machine resources: making C++ effective for low-
level, machine-near, programming as is essential in many application domains.
Powerful (Zero-overhead) abstraction mechanisms: making it possible to
escape the error-prone low-level programming by providing elegant, flexible,
and type-and-resource-safe, yet efficient facilities needed for higher-level
programming.

This book teaches both levels. We use the implementation of higher-level


abstractions as our primary examples to introduce low-level language features and
programming techniques. The aim is always to write code at the highest level
affordable, but that often requires a foundation built using lower-level facilities and
techniques. We aim for you to master both levels.

0.2.1 A note to students


AA
Many thousands of first-year university students taught using the first two editions
of this book had never before seen a line of code in their lives. Most succeeded, so
you can do it, too.
You don’t have to read this book as part of a course. The book is widely used for
self-study. However, whether you work your way through as part of a course or
independently, try to work with others. Programming has an – unfair – reputation as
a lonely activity. Most people work better and learn faster when they are part of a
group with a common aim. Learning together and discussing problems with friends
is not cheating! It is the most efficient – as well as most pleasant – way of making
progress. If nothing else, working with friends forces you to articulate your ideas,
which is just about the most efficient way of testing your understanding and making
sure you remember. You don’t actually have to personally discover the answer to
every obscure language and programming environment problem. However, please
don’t cheat yourself by not doing the drills and a fair number of exercises (even if
no teacher forces you to do them). Remember: programming is (among other
things) a practical skill that you must practice to master.
Most students – especially thoughtful good students – face times when they
wonder whether their hard work is worthwhile. When (not if) this happens to you,
take a break, reread this chapter, look at the “Computers, People, and
Programming” and “Ideals and History” chapters posted on the Web (§0.4.1).
There, I try to articulate what I find exciting about programming and why I consider
it a crucial tool for making a positive contribution to the world.
Please don’t be too impatient. Learning any major new and valuable skill takes
time.
The primary aim of this book is to help you to express your ideas in code, not to
teach you how to get those ideas. Along the way, we give many examples of how
we can address a problem, usually through analysis of a problem followed by
gradual refinement of a solution. We consider programming itself a form of problem
solving: only through complete understanding of a problem and its solution can you
express a correct program for it, and only through constructing and testing a
program can you be certain that your understanding is complete. Thus,
programming is inherently part of an effort to gain understanding. However, we aim
to demonstrate this through examples, rather than through “preaching” or
presentation of detailed prescriptions for problem solving.
Another random document with
no related content on Scribd:
The Confession of Agnes Sympson to King
James.
“Item.—Fyled and convict for samecle, as she confest before his
Majesty that the devil in man’s likeness met her going out in the
fields, from her own house a Keith, betwixt five and six at even, being
alone, and commendit her to be at Northborrick Kirk the next night.
And she passed then on horseback, conveyed by her good-son called
John Cooper, and lighted at the Kirk-yard, or a little before she came
to it, about eleven hours at even. They danced along the Kirk-yard,
Geilie Duncan plaid to them on a trump, John Fien, mussiled, led all
the rest; the said Agnes and her daughter followed next. Besides
there were Kate Grey, George Moile’s wife, Robert Guerson,
Catherine Duncan Buchanan, Thomas Barnhill and his wife, Gilbert
Macgil, John Macgil, Catherine Macgil, with the rest of their
complices, above an hundred persons, whereof there were six men,
and all the rest women. The women made first their homage and
then the men. The men were turned nine times Widdershins about,
and the women six times. John Fien blew up the doors and in the
lights, which were like mickle black candles sticking round about the
pulpit. The devil started up himself in the pulpit, like a mickle black
man, and every one answered here. Mr. Robert Guerson being
named, they all ran hirdie girdie, and were angry; for it was promised
he should be called Robert the Comptroller, alias Rob the Rowar, for
expriming of his name. The first thing he demandit was, as they kept
all promise, and been good servants, and what they had done since
the last time they convened. At his command they opened up three
graves, two within, and one without the Kirk, and took off the joints
of their fingers, toes, and neise, and parted them amongst them: and
the said Agnes Sympson got for her part a winding-sheet and two
joints. The devil commandit them to keep the joints upon them while
they were dry, and then to make a powder of them to do evil withal.
Then he commandit them to keep his commandments, which were to
do all the evil they could. Before they departed they kissed his breech
[the record speaks more broad.] He [meaning the devil] had on him
ane gown and ane hat, which were both black: and they that were
assembled, part stood and part sate: John Fien was ever nearest the
devil, at his left elbock; Graymarcal keeped the door.”
The Scotch accent has been here retained for the better
authenticity of the matter; the confession here given being, in all
probability, a principal reason why King James changed his opinion
relative to the existence of witches; which, it was reported, he was
inclined to think were mere conceits; as he was then but young (not
above five or six and twenty years of age) when this examination took
place before him; and part of the third chapter of his Demonologie
appears to be a transcript of this very confession.
Agnes Sympson was remarkable for her skill in diseases, and
frequently, it is said, took the pains and sickness of the afflicted upon
herself to relieve them, and afterwards translated them to a third
person: she made use of long Scriptural rhymes and prayers,
containing the principal points of Christianity, so that she seemed
not so much a white witch as a holy woman. She also used
nonsensical rhymes in the instruction of ignorant people, and taught
them to say the white and black Pater-noster in metre, in set forms,
to be used morning and evening; and at other times, as occasion
might require.
The White Pater-noster runs thus:—
God was my foster,
He fostered me
Under the book of Palm tree.
St. Michael was my dame,
He was born at Bethlehem.
He was made of flesh and blood,
God send me my right food;
My right food, and dyne too,
That I may too yon kirk go,
To read upon yon sweet book,
Which the mighty God of heaven shook.
Open, open, heaven’s yaits,
Steik, steik, hell’s yaits,
All saints be the better,
That hear the white prayer, Pater-noster.
The Black Pater-noster.
Four neuks in this house for holy angels,
A post in the midst, that Christ Jesus,
Lucas, Marcus, Mathew, Joannes,
God be unto this house, and all that belong us.

Whenever she required an answer from the devil, on any occasion,


he always appeared to her in the shape of a dog. And when she
wished him to depart, she conjured him in the following manner,
namely: “I charge thee to depart on the law thou livest on:” this it is
said was the language with which she dismissed him, after consulting
with him on old Lady Edmiston’s sickness. The manner in which she
raised the devil was with these words: “Elia come and speak to me;”
when he never failed to appear to her in the shape of a dog, as usual.
Her sailing with her Kemmers and fellow witches in a boat is related
as a very remarkable story, where the devil caused them all to drink
good wine and beer without money; and of her neither seeing the
sailors nor they her; and of the storm which the devil raised, whereby
the ship perished; also her baptizing, and using other ceremonies
upon a cat, in the company of other witches, to prevent Queen Anne
from coming to Scotland.
That which is most remarkable in John Fein, is the devil appearing
to him, not in black, but white raiment, although he proposed as
hellish a covenant to him as any in the black costume. His skimming
along the surface of the sea with his companions—his foretelling the
leak in the Queen’s ship—his raising a storm by throwing a cat into
the sea, during the King’s voyage to Denmark—his raising a mist on
the King’s return, by getting Satan to cast a thing like a foot-ball into
the sea, which caused such a smoke, as to endanger his Majesty
being driven on the coast of England—his opening locks by means of
sorcery, by merely blowing into a woman’s hand while she sat by the
fire—his embarking in a boat with other witches, sailing over the sea,
getting on board of a ship, drinking wine and ale there, and
afterwards sinking the vessel with all on board—his kissing Satan’s —
e again, at another conventicle—his being carried into the air, in
chasing a cat, for the purpose of raising a storm, according to Satan’s
prescription. He pretended also to tell any man how long he would
live, provided he told him the day of his birth.
SORCERY.

The crime of witchcraft, or divination, by the assistance of evil


spirits.
Sorcery is held by some to be properly what the ancients called
Sortilegium, or divination by means of Sortes or lots.
Lord Coke (3 Instit. fol. 44,) describes a Sorcerer, qui utitur
sortibus, et incantationibus dæmonium. Sorcery, by Stat. 1o.Jac. is
felony. In another book it is said to be a branch of heresy; and by
Stat. 12, Carolus II. it is excepted out of the general pardons.
Sorcery is pretended to have been a very common thing formerly;
the credulity, at least, of those ages made it pass for such; people
frequently suffered for it. In a more enlightened and less believing
age, sorcery has fled before the penetrating rays of science, like every
other species of human superstition and complicated diablerie. For,
indeed, it is a very probable opinion, that the several glaring
instances of sorcery we meet, in our old law books and historians, if
well inquired into, would be found at bottom, to have more human
art and desperate malignity and vindictive cunning about them, than
of demoniacal and preternatural agency. Were it not for a
wellregulated police acting under wise regulations for the safety and
harmony of society, sorcerers and evil spirits would be equally as
prevalent and destructive at the present day, as they were some two
or three hundred years ago.
SORTES.—SORTILEGIUM.

The ancients had a method of deciding dubious cases, where there


appeared no ground for a preference, by Sortes or lots, as in casting
of dice, drawing tickets, and various other ways, many of which are
still adopted.
The ancient sortes or lots, were instituted by God himself; and in
the Old Testament we meet with many standing and perpetual laws,
and a number of particular commands, prescribing and regulating
the use of them. Thus Scripture informs us that the lot fell on St.
Matthias, when a successor to Judas in the apostolate was to be
chosen. Our Saviour’s garment itself was cast lots for. Sortiti sunt
Christo vestem.
The Sortes Prænestinæ were famous among the Greeks. The
method of these was to put a great number of letters, or even whole
words, into an urn; to shake them together, and throw them out; and
whatever should chance to be made out in the arrangement of the
letters, &c. composed the answer of this oracle.
In what repute soever this mode of divination formerly might have
been, M. Dacier observes, that, in Cicero’s time, its credit was but
low; so much so, that none but the most credulous part of the
populace had recourse to it. Instead of this another kind of sortes
was introduced into Greece and Italy; which was, to take some
celebrated poet, as for instance Homer, Euripides, Virgil, &c., to
open the book, and whatever first presented itself to the eye on
opening, it thus was taken for the ordinance of heaven. This made
what was called the Sortes Homericæ and Sortes Virgilianæ, which
succeeded the use of the Sortes Prænestinæ.
This superstition passed hence into Christianity; and the
Christians took their sortes out of the Old and New Testament. The
first passage that presented itself on opening a book of Scripture, was
esteemed the answer of God himself. If the first passage that was
opened did not happen to be any thing to the purpose for which the
sortes were consulted, another book was opened, and so on until
something was met with that might, one way or the other, be taken
for an answer. This was called Sortes Sanctorum.
St. Augustine does not disapprove of this method of learning
futurity, provided it be not used for worldly purposes; and, in fact, he
owns having practised it himself.
Gregory of Tours adds, that the custom was to lay the Bible on the
altar, and to pray the Lord that he would discover by it what was to
come to pass. Indeed, instances of the use of the Sanctum
Sanctorum are very frequent in history. Mr. Fleury tells us that
Heraclius, in his war against Cossoes, to learn where he should take
up his winter quarters, purified his army for three days, and then
opened the Gospels, and discovered thereby that the place appointed
for them was in Albania.
Gilbert of Nogent informs us, that, in his time, viz. about the
beginning of the twelfth century, the custom was, at the consecration
of bishops, to consult the Sortes Sanctorum, to learn the success,
fate, and other particulars of their episcopate. This practice is
founded on a supposition that God presides over the Sortes, and this
is strengthened by Prov. chap. xvi. verse 33, where it is said, “The lot
is cast into the lap, but the whole disposing thereof is of the Lord.”
In fact, many divines have held, and even now many of them still
hold, that the lot is conducted in a particular manner by Providence;
that it is an extraordinary manner, in which God declares his will by
a kind of immediate revelation. The Sortes Sanctorum, however,
were condemned by the council of Agda, in 506, at the time they
were beginning to take footing in France.
This practice crept in among the Christians, of casually opening
the sacred books for directions in important circumstances; to know
the consequences of events; and what they had to fear from their
rulers.
This consultation of the divine will from the Scriptures, was of two
kinds:—The first consisted, as I have said, in casually opening those
writings, but not before the guidance of heaven had been implored
with prayer, fasting, and other acts of religion. The second was much
more simple: the first words of the Scripture, which were singing or
reading, at the very instant when the person, who came to know the
disposition of heaven, entered the church, being considered either an
advice, or a prognostic.
St. Austin, in his epistle to Januarius, justly condemns the
practice; but St. Gregory of Tours, by the following instance, which
he relates as having happened to himself, shows that he entertained
a better opinion of it:—“Leudastus, Earl of Tours,” says he, “who was
for ruining me with Queen Fredegonde, coming to Tours, big with
evil designs against me, I withdrew to my oratory under a deep
concern, where I took the Psalms, to try if, at opening them, I should
light upon some consoling verse. My heart revived within me, when I
cast my eyes on this of the 77th Psalm, ‘He caused them to go on with
confidence, whilst the sea swallowed up their enemies.’ Accordingly,
the Count spoke not a word to my prejudice; and leaving Tours that
very day, the boat in which he was, sunk in a storm, but his skill in
swimming saved him.”
The following is also from the same author. “Chranmes having
revolted against Clotaire, his brother, and being at Dijon, the
ecclesiastics of the place, in order to foreknow the success of this
procedure, consulted the sacred books; but instead of the Psalms,
they made use of St. Paul’s Epistles, and the Prophet Isaiah. Opening
the latter they read these words: ‘I will pluck up the fence of my
vineyard, and it shall be destroyed, because instead of good, it has
brought forth bad grapes.’ The Epistles agreeing with the prophecy, it
was concluded to be a sure presage of the tragical end of Cranmes.”
St. Consortia, in her youth, was passionately courted by a young
man of a very powerful family, though she had formed a design of
taking the veil. Knowing that a refusal would expose her parents to
many inconveniences, and perhaps to danger, she desired a week’s
time to determine her choice. At the expiration of this time, which
she had employed in devout exercises, her lover, accompanied by the
most distinguished matrons of the city, came to know her answer. “I
can neither accept of you nor refuse you,” said she, “every thing is in
the hand of God: but if you will agree to it, let us go to the church,
and have a mass said; afterwards, let us lay the holy gospel on the
altar, and say a joint prayer; then we will open the book, to be
certainly informed of the divine will in this affair.” This proposal
could not with propriety be refused; and the first verse which met the
eyes of both, was the following: “Whosoever loveth father or mother
better than me, is not worthy of me.” Upon this, Consortia said, “You
see God claims me as his own;” and the lover acquiesced.
But about the eighth century, this practice began to lose ground, as
soon or late, reason and authority will get the better of that which is
founded on neither. It was proscribed by several popes and councils,
and in terms which rank it among Pagan superstitions. However,
some traces of this custom are found for several ages after, both in
the Greek and the Latin church. Upon the consecration of a bishop,
after laying the bible upon his head, a ceremony still subsisted, that
the first verse which offered itself, was accounted an omen of his
future behaviour, and of the good or evil which was reserved for him
in the course of his episcopacy. Thus, a Bishop of Rochester, at his
consecration by Lanfranc, Archbishop of Canterbury, had a very
happy presage in these words: “Bring hither the best robe, and put it
on him.” But the answer of the Scripture, at the consecration of St.
Lietbert, Bishop of Cambray, was still more grateful: “This is my
beloved son, in whom I am well pleased.” The death of Albert, Bishop
of Liege, is said to have been intimated to him by these words, which
the Archbishop, who consecrated him, found at the opening of the
New Testament, “And the king sent an executioner, and commanded
his head to be brought; and he went and beheaded him in the
prison.” Upon this the primate tenderly embracing the new bishop,
said to him with tears, “My son, having given yourself up to the
service of God, carry yourself righteously and devoutly, and prepare
yourself for the trial of martyrdom.” The Bishop was afterwards
murdered by the treacherous connivance of the Emperor Henry VI.
These prognostics were alleged upon the most important
occasions. De Garlande, Bishop of Orleans, became so odious to his
clergy, that they sent a complaint against him to Pope Alexander III.
concluding in this manner: “Let your apostolical hands put on
strength to strip naked the iniquity of this man; that the curse
prognosticated on the day of his consecration, may overtake him; for
the gospels being opened, according to custom, the first words were,
And the young man, leaving his linen cloth, fled from them naked.”
William of Malmsbury relates, that Hugh de Montaigne, Bishop of
Auxerre, was obliged to go to Rome, to answer different charges
brought against the purity of his morals, by some of his chapter; but
they who held with the bishop, as an irrefragable proof of his spotless
chastity, insisted that the prognostic on the day of his consecration
was, “Hail, Mary, full of grace.”
I proceed to the second manner of this consultation, which was to
go into a church with the intention of receiving, as a declaration of
the will of Heaven, any words of the Scripture which might chance to
be sung or read, at the moment of the person’s entrance. Thus, it is
said, St. Anthony, to put an end to his irresolution about retirement,
went to a church, where immediately hearing the deacon pronounce
these words, “Go sell all thou hast, and give it to the poor, then come
and follow me;” he applied them to himself, as a direct injunction
from God, and withdrew to that solitude for which he is so celebrated
among the Catholics.
The following passage from Gregory of Tours, is too remarkable to
be omitted. He relates that Clovis, the first Christian king of France,
marching against Alaric, King of the Visgoths, and being near the city
of Tours, where the body of St. Martin was deposited, he sent some
of his nobles, with presents to be offered at the saint’s tomb, to see if
they could not bring him a promising augury, while he himself
uttered this prayer “Lord, if thou wouldest have me punish this
impious people, the savage enemy of thy holy name, give me some
signal token, by which I may be assured that such is thy will.”
Accordingly, his messengers had no sooner set foot within the
cathedral, than they heard the priest chaunt forth this verse of the
eighteenth Psalm, “Thou hast girded me with strength for war, thou
hast subdued under me those that rose up against me.” Transported
at these words, after laying the presents at the tomb of the saint, they
hastened to the King with this favourable prognostic; Clovis joyfully
accepted it, and engaging Alaric, gained a complete victory.
Here also may be subjoined a passage in the history of St. Louis IX.
In the first emotions of his clemency, he had granted a pardon to a
criminal under sentence of death; but some minutes after, happening
to alight upon this verse of the Psalms, “Blessed is he that doth
righteousness at all times;” he recalled his pardon, saying, “The King
who has power to punish a crime, and does not do it, is, in the sight
of God, no less guilty than if he had committed it himself.”
The Sortes Sanctorum were fulminated against by various
councils. The council of Varres “forbade all ecclesiastics, under pain
of excommunication, to perform that kind of divination, or to pry
into futurity, by looking into any book, or writing, whatsoever.” The
council of Ayde, in 506, expressed itself to the same effect; as did
those of Orleans, in 511; and Auxerre, in 595. It appears, however, to
have continued very common, at least in England, so late as the
twelfth century: the council of Aenham, which met there in 1110,
condemned jointly, sorcerers, witches, diviners, such as occasioned
death by magical operations, and who practised fortune-telling by
the holy book-lots.
Peter de Blois, who wrote at the close of the twelfth century, places
among the sorcerers, those who, under the veil of religion, promised,
by certain superstitious practices, such as the lots of the Apostles and
Prophets, to discover hidden and future events: yet this same Peter
de Blois, one of the most learned and pious men of his age, in a letter
to Reginald, whose election to the see of Bath had a long time been
violently opposed, tells him, that he hopes he has overcome all
difficulties; and further, that he believes he is, or soon will be,
established in his diocese. “This belief,” says he, “I ground on a
dream I lately had two nights successively, of being at your
consecration; and also, that being desirous of knowing its certain
meaning, by lots of human curiosity, and the Psalter, the first which
occurred to me were, ‘Moses and Aaron among his priests.’”
Thus, though the ancient fathers, and, since them, others have in
general agreed, that the Sortes Sanctorum cannot be cleared of
superstition, though they assert that it was tempting God, to expect
that he would inform us of futurity, and reveal to us the secrets of his
will, whenever the sacred book is opened for such a purpose, though
it contain nothing which looks like a promise of that kind from God;
though so far from being warranted by any ecclesiastical law, it has
been condemned by several, and, at last, in more enlightened times,
has been altogether abolished, yet they do not deny, that there have
been occasions, when discreet and pious persons have opened the
sacred book, not to discover futurity, but to meet with some passage
to support them in times of distress and persecution.
SIBYLS.

This word is supposed to be formed of the two Greek words σιου


for Θεου Dei, and βουλη counsel.
The Sibyllæ of antiquity were virgin-prophetesses, or maids
supposed to be divinely inspired; who, in the height of their
enthusiasm, gave oracles, and foretold things to come.
Authors are at variance with respect to the number of sibyls.
Capella reckons but two; viz. Erophyte of Troy, called Sibylla
Phrygia; and Sinuachia of Erythræa. Solinus mentions three, viz.
Cumæa, Delphica, and Erythræa. Ælian makes their number four,
and Varro increases it to ten, denominating them from the places of
their birth; the Persian, Delphic, Cumæan, Erythræan, Samian,
Cuman, Hellespontic or Troiad, Phrygian, and Tiburtine. Of these
the most celebrated are, the Erythræan, Delphic, and Cumæan
Sibyls.
The sibylline oracles were held in great veneration by the more
credulous among the ancients; but they were much suspected by the
better informed. The books wherein they were written, were kept by
the Romans with infinite care; and nothing of moment was
undertaken without consulting them. Tarquin first committed them
to the custody of two patrician priests for that purpose.
TALISMANS.

Magical figures, engraven or cut under superstitious observances


of the characterisms and configurations of the heavens, are called
talismans; to which some astrologers, hermetical philosophers, and
other adepts, attribute wonderful virtues, particularly that of calling
down celestial influences.
The author of a book, intituled Talismans Justifies, pronounces a
talisman is the seal, figure, character, or image of a heavenly sign,
constellation, or planet, engraven on a sympathetic stone, or on a
metal corresponding to the star, &c. in order to receive its influences.
The talismans of the Samothracians, so famous of old, were pieces
of iron formed into certain images, and set in rings, &c. They were
held as preservatives against all kinds of evils. There were other
talismans taken from vegetables, and others from minerals.
Three kinds of Talismans were usually distinguished, viz.
Astronomical, which are known by the signs or constellations of the
heavens engraven upon them, with other figures, and some
unintelligible characters. Magical, which bear very extraordinary
figures, with superstitious words and names of angels unheard of.
And mixt, which consist of signs and barbarous words; but have no
superstitious ones, or names of angels.
It is maintained by some rabbins, that the brazen serpent raised by
Moses in the Wilderness, for the destruction of the serpents that
annoyed the Israelites, was properly a Talisman.
All the miraculous things wrought by Apollonius Tyanæus are
attributed to the virtue and influence of Talismans; and that wizard,
as he is called, is even said to have been the inventor of them.
Some authors take several Runic medals,—medals, at least, whose
inscriptions are in the Runic characters,—for talismans, it being
notorious, that the northern nations, in their heathen state, were
much devoted to them. M. Keder, however, has shewn, that the
medals here spoken of are quite other things than talismans.
PHILTERS, CHARMS, &c.

A drug, or other preparation, used as a pretended charm to excite


love. These are distinguished into true and spurious: the spurious are
spells or charms supposed to have an effect beyond the ordinary law
of nature, by some inherent magic virtue; such are those said to be
possessed formerly by old women, witches, &c.—The true Philters
were supposed to operate by some natural and magnetical power.
There are many enthusiastic and equally credulous authors, who
have encouraged the belief in the reality of these Philters; and
adduce matter in fact in confirmation of their opinions, as in all
doubtful cases. Among these may be quoted Van Helmont, who says,
that by holding a certain herb in his hand, and afterwards taking a
little dog by the foot with the same hand, the animal followed him
wherever he went, and quite deserted his former master. He also
adds, that Philters only require a confirmation of Mumia[51]; and on
this principle he accounts for the phenomena of love transplanted by
the touch of an herb; for, says he, the heat communicated to the
herb, not coming alone, but animated by the emanations of the
natural spirits, determines the herb towards the man, and identifies
it to him. Having then received this ferment, it attracts the spirit of
the other object magnetically, and gives it an amorous motion. But
all this is mere absurdity, and has fallen to the ground with the other
irrational hypothesis from the same source.
HELL,

A place of punishment, where, we are told in Scripture, the wicked


are to receive the reward of their evil deeds, after this life. In this
sense, hell is the antithesis of HEAVEN.
Among the ancients hell was called by various names, Ταρταρος,
Ταρταρᾶ, Tartarus, Tartara; Ἁδης, Hades, Infernus, Inferna, Inferi,
&c.—The Jews, wanting a proper name for it, called it Gehenna, or
Gehinnon, from a valley near Jerusalem, wherein was Tophet, or
place where a fire was perpetually kept.
Divines reduce the torments of hell to two kinds, pœna damni, the
loss and privation of the beatific vision; and pœna sensus, the
horrors of darkness, with the continual pains of fire inextinguishable.
Most nations and religions have a notion of a hell. The hell of the
poets is terrible enough: witness the punishment of Tityus,
Prometheus, the Danæids, Lapithæ, Phlegyas, &c. described by Ovid,
in his Metamorphosis. Virgil, after a survey of Hell, Æneid, lib. vi.
declares, that if he had a hundred mouths and tongues, they would
not suffice to recount all the plagues of the tortured. The New
Testament represents hell as a lake of fire and brimstone; and a
worm which dies not, &c. Rev. xx. 10, 14, &c. Mark ix. 43, &c. Luke
xvi. 23, &c.
The Caffres are said to admit thirteen hells, and twenty-seven
paradises; where every person finds a place suited to the degree of
good or evil he has done.
There are two great points of controversy among writers, touching
hell: the first, whether there be any local hell, any proper and specific
place of torment by fire? the second, whether the torments of hell are
to be eternal?
I. The locality of hell, and the reality of the fire thereof, have been
controverted from the time of Origen. That father, in his treatise
Περι Αρχαν, interpreting the scripture account metaphorically,
makes hell to consist not in eternal punishments, but in the
conscience of sinners, the sense of their guilt, and the remembrance
of their past pleasures. St. Augustine mentions several of the same
opinion in his time; and Calvin, and many of his followers, have
embraced it in ours.
The retainers to the contrary opinion, who are much the greatest
part of mankind, are divided as to situation, and other circumstances
of this horrible scene. The Greeks, after Homer, Hesiod, &c.
conceived hell, τοπον τινα ὐπο την γην μεγσν, &c. a large and dark
place under the earth.—Lucian, de Luctu; and Eustathius, on Homer.
Some of the Romans lodged in the subterranean regions directly
under the lake Avernus, in Campania, which they were led to from
the consideration of the poisonous vapours emitted by that lake.
Through a dark cave, near this lake, Virgil makes Æneas descend to
hell.
Others placed hell under Tenarus, a promontory of Laconia; as
being a dark frightful place, beset with thick woods, out of which
there was no finding a passage. This way, Ovid says, Orpheus
descended to hell. Others fancied the river or fountain of Styx, in
Arcadia, the spring-head of hell, by reason the waters thereof were
mortal.
But these are all to be considered as only fables of poets; who,
according to the genius of their art, allegorizing and personifying
every thing, from the certain death met withal in those places, took
occasion to represent them as so many gates, or entering-places into
the other world.
The primitive Christians conceiving the earth a large extended
plain, and the heavens an arch drawn over the same, took hell to be a
place in the earth, the farthest distant from the heavens; so that their
hell was our antipodes.
Tertullian, De Anima, represents the Christians of his time, as
believing hell to be an abyss in the centre of the earth: which opinion
was chiefly founded on the belief of Christ’s descent into hades, hell,
Matt. xii. 40.
Mr. Wiston has lately advanced a new opinion. According to him,
the comets are to be conceived as so many hells, appointed in the
course of their trajectories, or orbits, alternately to carry the damned
into the confines of the sun, there to be scorched by his flames, and
then to return them to starve in the cold, dreary, dark regions,
beyond the orb of Saturn.
The reverend and orthodox Mr. T. Surnden, in an express Inquiry
into the nature and place of Hell, not contented with any of the
places hitherto assigned, contends for a new one. According to him,
the sun itself is the local hell.
This does not seem to be his own discovery: it is probable he was
led into it by that passage in Rev. xvi. 8, 9. Though it must be added,
that Pythagoras seems to have the like view, in that he places hell in
the sphere of fire; and that sphere in the middle of the universe. Add,
that Aristotle mentions some of the Italic or Pythagoric school, who
placed the sphere of fire in the sun, and even called it Jupiter’s
Prison.—De Cælo, lib. ii.
To make way for his own system, Mr. Swinden undertakes to
remove hell out of the centre of the earth, from these two
considerations:—1. That a fund of fuel or sulphur, sufficient to
maintain so furious and constant a fire, cannot be there supposed;
and, 2. That it must want the nitrous particles in the air, to sustain
and keep it alive. And how, says he, can such fire be eternal, when by
degrees the whole substance of the earth must be consumed thereby?
It must not be forgot, however, that Tertullian had long ago
obviated the former of these difficulties, by making a difference
between arcanus and publicus ignis, secret and open fire: the nature
of the first, according to him, is such, as that it not only consumes,
but repairs what it preys upon. The latter difficulty is solved by St.
Augustine, who alleges, that God supplies the central fire with air, by
a miracle.
Mr. Swinden, however, proceeds to shew, that the central parts of
the earth are possessed by water rather than fire; which he confirms
by what Moses says of water under the earth, Exod. xx. from Psalm
xxiv. 2, &c.
As a further proof, he alleges, that there would want room in the
centre of the earth, for such an infinite host of inhabitants as the
fallen angels and wicked men.
Drexelius, we know, has fixed the dimensions of hell to a German
cubic mile, and the number of the damned to an hundred thousand
millions: De Damnator, Carcer, &c. Rogo. But Mr. Swinden thinks
he need not to have been so sparing in his number, for that there
might be found an hundred times as many; and that they must be
insufferably crowded in any space he could allow them on our earth.
It is impossible, he concludes, to stow such a multitude of spirits in
such a scanty apartment, without a penetration of dimensions,
which, he doubts, in good philosophy, even in respect of spirits: “If it
be (he adds,) why God should prepare, i. e. make, a prison for them,
when they might all have been crowded together into a baker’s oven.”
p. 206.
His arguments for the sun’s being the local hell are: 1. Its capacity.
Nobody will deny the sun spacious enough to receive all the damned
conveniently; so that there will be no want of room. Nor will fire be
wanting, if we admit of Mr. Swinden’s argument against Aristotle,
whereby he demonstrates, that the sun is hot, p. 208, et seq. The
good man is “filled with amazement to think what Pyrenian
mountains of sulphur, how many Atlantic oceans of scalding
bitumen, must go to maintain such mighty flames as those of the
sun; to which our Ætna and Vesuvius are mere glow-worms.” p. 137.
2. Its distance and opposition to the empyreum, which has usually
been looked upon as the local heaven: such opposition is perfectly
answerable to that opposition in the nature and office of a place of
angels and devils, of elect and reprobate, of glory and horror, of
hallelujahs and cursings; and the distance quadrates well with Dives
seeing Abraham afar off, and the great gulph between them; which
this author takes to be the solar vortex.
3. That the empyreum is the highest, and the sun the lowest place
of the creation; considering it as the centre of our system; and that
the sun was the first part of the visible world created; which agrees
with the notion of its being primarily intended or prepared to receive
the angels, whose fall he supposes to have immediately preceded the
creation.
4. The early and almost universal idolatry paid to the sun; which
suits well with the great subtilty of that spirit, to entice mankind to
worship his throne.

You might also like