Bjarne Stroustrup's FAQ

Modified March 1, 2020.

These are questions that people ask me often. If you have better questions or comments on the answers, feel free to email me. Please remember that I can't spend all of my time improving my homepages.

This page concentrates on personal opinions and general questions related to philosophy. For questions that more directly relate to C++ language features and the use of C++, see The C++ Foundation's FAQ or my C++ style and technique FAQ. For C++ terminology and concepts, see my C++ glossary. For links to useful sources of C++ information, see my C++ page and my C++11 FAQ. For information about my books (incl. reviews and support information), see my book list. For papers and ISBNs for translations of my books, see my publication list.

Translations:

Index

For people who can't receive sound, here is a suggestion: Both of my names are pronounced with two syllables: Bjar-ne Strou-strup. Neither the B nor the J in my first name are stressed and the NE is rather weak so maybe Be-ar-neh or By-ar-ne would give an idea. The first U in my second name really should have been a V making the first syllable end far down the throat: Strov-strup. The second U is a bit like the OO in OOP, but still short; maybe Strov-stroop will give an idea.

Yes, this probably is the most frequently asked question :-)

P.S. My first name is Bjarne - not Bjorn (not a name), Bjørn (a related but different name), nor Barney (an unrelated name). My second name is Stroustrup - not Stroustroup, Stroustrop, Strustrup, Strustrop, Strustroup, Straustrup, nor Straustroup (documents using each of these misspellings can be found using google).

Here are links to

Also, if you mail me, please try to make sure that I can reply to you. I really hate it when I have written and sent a reply, just to find that the return address is invalid or inaccessible.

Two kinds of messages have a relatively high chance of getting lost: homework questions and questions of the form "how do I use this proprietary library?". I'm a bit sad about not answering the latter questions because often the person asking doesn't understand that the DOS, Windows, or whatever interface from C++ is not part of the C++ standard (and I cannot keep up with the huge number of C++ libraries). If you fail to receive an answer, please consider if your question was of one of these kinds.

Also, unless you give your name, I am now likely to delete the message unread. This is a new policy. I was never a great fan of pseudonyms, but I find that the chance of a polite technical conversation with the kind of person who thinks it cool to hide behind a name like suuupergeeek or coolGuy3 is getting too low for me to bother trying.

What looks "cool and modern" to someone is often considered bad taste by someone else, and fashions change fast. Also, very plain html downloads and displays faster than anything else, and many people still suffer from slow web connections.

Classes are there to help you organize your code and to reason about your programs. You could roughly equivalently say that classes are there to help you avoid making mistakes and to help you find bugs after you do make a mistake. In this way, classes significantly helps maintenance.

A class is the representation of an idea, a concept, in the code. An object of a class represents a particular example of the idea in the code. Without classes, a reader of the code would have to guess about the relationships among data items and functions - classes make such relationships explicit and "understood" by compilers. With classes, more of the high-level structure of your program is reflected in the code, not just in the comments.

A well-designed class presents a clean and simple interface to its users, hiding its representation and saving its users from having to know about that representation. If the representation shouldn't be hidden - say, because users should be able to change any data member any way they like - you can think of that class as "just a plain old data structure"; for example:

struct Pair { string name, value; };

When designing a class, it is often useful to consider what's true for every object of the class and at all times. Such a property is called an invariant. For example, the invariant of a vector could be that its representation consists of a pointer to a number of elements and that number of elements is stored in an integer. It is the job of every constructor to establish the class invariant, so that every member function can rely on it. Every member function must leave the invariant valid upon exit. This kind of thinking is particularly useful for classes that manage resource, such as locks, sockets, and files. For example, a file handle class will have the invariant that it holds a pointer to an open file. The file handle constructor opens the file. Destructors free resources acquired by constructors. For example, the destructor for a file handle closes the file opened by the constructor:

class File_handle { public: File_handle(const char* n, const char* rw) { f = fopen(n,rw); if (f==0) throw Open_failure(n); } ~File_handle() { fclose(f); } // destructor // ... private: FILE* f; };

There are lots of definitions of "object oriented", "object-oriented programming", and "object-oriented programming languages". For a longish explanation of what I think of as "object oriented", read Why C++ isn't just an object-oriented programming language. That said, object-oriented programming is a style of programming originating with Simula (more than 40 years ago!) relying of encapsulation, inheritance, and polymorphism. In the context of C++ (and many other languages with their roots in Simula), it means programming using class hierarchies and virtual functions to allow manipulation of objects of a variety of types through well-defined interfaces and to allow a program to be extended incrementally through derivation.

See What's so great about classes? for an idea about what great about "plain classes". The point about arranging classes into a class hierarchy is to express hierarchical relationships among classes and use those relationships to simplify code.

To really understand OOP, look for some examples. For example, you might have two (or more) device drivers with a common interface:

class Driver { // common driver interface public: virtual int read(char* p, int n) = 0; // read max n characters from device to p // return the number of characters read virtual bool reset() = 0; // reset device virtual Status check() = 0; // read status };

class Driver1 : public Driver { // a driver public: Driver1(Register); // constructor int read(char*, int n); bool reset(); Status check(); private: // implementation details, incl. representation }; class Driver2 : public Driver { // another driver public: Driver2(Register); int read(char*, int n); bool reset(); Status check(); private: // implementation details, incl., representation };

void f(Driver& d) // use driver { Status old_status = d.check(); // ... d.reset(); char buf[512]; int x = d.read(buf,512); // ... }

void g() { Driver1 d1(Register(0xf00)); // create a Driver1 for device // with device register at address 0xf00 Driver2 d2(Register(0xa00)); // create a Driver2 for device // with device register at address 0xa00 // ... int dev; cin >> dev; if (dev==1) f(d1); // use d1 else f(d2); // use d2 // ... }

Please note that object-oriented programming is not a panacea. "OOP" does not simply mean "good" - if there are no inherent hierarchical relationships among the fundamental concepts in your problem then no amount of hierarchy and virtual functions will improve your code. The strength of OOP is that there are many problems that can be usefully expressed using class hierarchies - the main weakness of OOP is that too many people try to force too many problems into a hierarchical mould. Not every program should be object-oriented. As alternatives, consider plain classes, generic programming, and free-standing functions (as in math, C, and Fortran).

Generic programming is programming based on parameterization: You can parameterize a type with another (such as a vector with its element types) and an algorithm with another (such as a sort function with a comparison function). The aim of generic programming is to generalize a useful algorithm or data structure to its most general and useful form. For example, a vector of integers is fine and so is a function that finds the largest value in a vector of integers. However, a generic solution that provides a vector of any type the user cares to use and a function that finds the largest value in any vector is better still:

vector<string>::iterator p = find(vs.begin(), vs.end(), "Grail"); vector<int>::iterator q = find(vi.begin(), vi.end(), 42);

Generic programming is in some ways more flexible than object-oriented programming. In particular, it does not depend on hierarchies. For example, there is no hierarchical relationship between an int and a string. Generic programming is generally more structured than OOP; in fact, a common term used to describe generic programming is "parametric polymorphism", with "ad hoc polymorphism" being the corresponding term for object-oriented programming. In the context of C++, generic programming resolves all names at compile time; it does not involve dynamic (run-time) dispatch. This has led generic programming to become dominant in areas where run-time performance is important.

Please note that generic programming is not a panacea. There are many parts of a program that need no parameterization and many examples where run-time dispatch (OOP) is needed.

to access hardware directly (e.g. to treat an integer as a pointer to (address of) a device register)

to achieve optimal run-time and space performance (e.g. unchecked access to elements of an array and unchecked access to an object through a pointer)

to be compatible with C

don't use casts

keep arrays out of interfaces (hide them in the innards of high-performance functions and classes where they are needed and write the rest of the program using proper strings, vectors, etc.)

avoid void* (keep them inside low-level functions and data structures if you really need them and present type safe interfaces, usually templates, to your users)

avoid unions

if you have any doubts about the validity of a pointer, use a smart pointer instead,

don't use "naked" news and deletes (use containers, resource handles, etc., instead)

don't use ...-style variadic functions ("printf style")

Avoid macros excpt for include guards

For an ambitious project to make C++ easier to use and safer without damaging its efficiency or flexibility, see the Core C++ Guidelines.

For people who haven't programmed before or come from another language and want a relatively gentle introduction to modern C++, consider Programming: Principles and Practice using C++. This is the book I wrote for a freshman (1st year university students) programming class and it has benefitted from three years of classroom use.

For people who are programmers and willing to learn new concepts and techniques from a classical textbook, I recommend The C++ Programming Language (4th edition). The book is aimed at programmers with some experience and a wish to master C++. It is not aimed at non-programmers trying to learn their first programming language or casual programmers trying to gain a superficial understanding of C++ as fast as possible. Consequently, this book focuses on concepts and techniques and goes to some pain to be complete and precise. It describes "pure C++," that is, the language independently of any particular software development environment or foundation library (except the standard library, of course). It contain comprehensive coverage of the standard library.

If you are already an experienced programmer and want a quick overview of what C++ has to offer, consider A Tour of C++. It presents the major features of C++ and its standard library in 180 pages.

If you want to know why C++ is the way it is, have a look at The Design and Evolution of C++ (D&E). Understanding the design criteria and constraints helps writing better programs.

At TAMU, we use Programming: Principles and Practice using C++ to get freshmen (1st year students) through the fundamentals of C++ and the programming techniques it support (notably object-oriented programming and generic programming) in a semester.

On the other hand, if you want to be fully comfortable with all the major C++ language constructs, with data abstraction, Object-Oriented programming, generic programming, Object-Oriented design, etc., you can easily spend a year or two - if you aren't already acquainted with those techniques (say, from Java or C#).

Is that then the time it takes to learn C++? Maybe, but then again, that is the timescale we have to consider to become better designers and programmers. If a dramatic change of the way we work and think about building systems isn't our aim, then why bother to learn a new language? Compared to the time required to learn to play the piano well or to become fluent in a foreign (natural) language, learning a new and different programming language and programming style is easy.

For more observations about learning C++ see D&E or a note from comp.lang.c++ that I wrote some time ago.

See Learning Standard C++ as a New Language for a discussion of the choice of C++ constructs, techniques, and libraries for early learning. For an example of books that takes that approach systematically, see Stroustrup: Programming: Principles and Practice using C++ and Koenig&Moo: "Accelerated C++" from Addison Wesley's C++ In Depth series.

You'll need a textbook for learning C++. This is the case even when your implementation comes with ample on-line documentation. The reason is that language and library documentation together with sample code are not good teachers of concepts. Typically such sources are silent about why things are the way they are and what benefits you can expect (and which you shouldn't expect) from a technique. Focus on concepts and techniques rather than language-technical details.

When choosing a book, look for one that presents Standard C++ and use the standard library facilities in an integrated manner from the start. For example, reading a string from input should look something like

string s; // Standard C++ style cin >> s;

char s[MAX]; /* Standard C style */ scanf("%s",s);

I recommend Programming: Principles and Practice using C++, but remember that no one book is the best for everyone. Have a look at the book reviews on the ACCU (The Association of C and C++ Users) site.

Aim to write idiomatic C++: avoid simply writing code in the style of your previous language using C++ syntax; there is little to be gained from simply changing syntax.

Also, no, I will not suggest "a good project for a student to work on". My experience is that learning enough about a student and his/her course to know what level of difficulty is required and what kind of project is of interest takes time. To think of a good project is then non-trivial, and to explain exactly what the project is and how to approach it can take several messages and several hours. I just don't have that kind of time. Remember, these request come at least weekly. Finally, some students seem to have the idea that if I suggest a project, I am morally obliged to provide quite detailed help in its completion.

Ideas: Look at the exercises in TC++PL or other good textbooks. Many of those exercises are designed to keep a student busy for several days, and reading those exercises can inspire an enterprising student to so something similar. Or look at the non-computer-science part of your world: Maybe a biology project could use support for a new measurement device or a friend studying history could use an improved database interface. Many of the best projects and the best uses of computers are outside traditional computer science.

See also my C++ style and techniques FAQ. Real novices facing their first "read some data, do something to it, and produce some output" exercise might be interested in a very simple program or a program reading a string from input.

C++14 is even better.

The current standard, C++14, was approved in 2014 and good implementationt are already shipping. C++11/C++14 is described in the current editions of my books.

The C++ standard (ISO/IEC 14882) is available for downloading at the the ANSI Electronic Store. Search for "14882", to find "INCITS/ISO/IEC 14882-2003 Programming Languages - C++" The cost is (as I write this) US$30.00 payable on-line via credit card. The downloaded document is in PDF form, about 3Mb total size.

A late working paper is available for free. This is close to the final draft international standard formally accepted by a 21-0 national vote in August 2011.

Be warned that the standard is not a tutorial; even expert programmers will do better learning about C++ and new C++ features from a textbook.

See my C++11 FAQ for references to C++11 material.

Most of the features I dislike from a language-design perspective (e.g., the declarator syntax and array decay) are part of the C subset of C++ and couldn't be removed without doing harm to programmers working under real-world conditions. C++'s C compatibility was a key language design decision rather than a marketing gimmick. Compatibility has been difficult to achieve and maintain, but real benefits to real programmers resulted, and still result today. By now, C++ has features that allow a programmer to refrain from using the most troublesome C features. For example, standard library containers such as vector, list, map, and string can be used to avoid most tricky low-level pointer manipulation.

There is a long list of C++11 extensions to C++98 on C++11 page. C++14 is a relatively minor improvement over C++11, intended to complete C++11, rather than enabling new programming techniques.

It is now shipping from amazon, from the publisher , and elsewhere.

There are no current plans for a 5th edition.

A summary:

TC++PL4: For programmers who wants to know modern C++ in depth

Tour++: For programmers who wants an overview of modern C++

PPP: For novices and programmers with a weak understanding of C++

D&E: For people interested in design principles and history

Others: Don't read them; they are outdated

Addison-Wesley offers electronic versions through Safari online books service and elsewhere.

For an incomplete list of C++ implementations, see my C++ compilers list.

Also, where possible, prefer the standard library to non-standard "foundation libraries" and try to minimize use of proprietary extensions.

The problem seems to be an interesting little exercise that John Bentley once proposed to me: Insert a sequence of random integers into a sorted sequence, then remove those elements one by one as determined by a random sequece of positions: Do you use a vector (a contiguously allocated sequence of elements) or a linked list? For example, see Software Development for Infrastructure. I use this example to illustrate some points, encourage thought about algorithms, data structures, and machine architecture, concluding:

don't store data unnecessarily,

keep data compact, and

access memory in a predictable manner.

I used that example in several talks, notably:

I have been using the example for years, and had graduate students implement and measure dozens of variants of this exercise and different exercises. Examples and measurements by others can be found on the Web. Of course,

I have tried maps (they are much better than lists, but still slower than vectors)

I have tried much larger elements sizes (eventually lists come into their own)

I have used binary search and direct insertion for vectors (yes, they speed up even further)

I checked my theory (no I'm not violating any big-O complexity rule; it is just that some operations can be dramatically more expensive for one data structure compared to another)

I have preallocated links (that's better than std::list but the traversal still kills performance)

but the traversal still kills performance) I have used singly-linked lists, forward_list s, (that doesn't make much difference, but makes it a bit harder to ensure that the user code is 100% equivalent)

s, (that doesn't make much difference, but makes it a bit harder to ensure that the user code is 100% equivalent) I know (and say) that 500K lists are not common (but that doesn't matter for my main point). We use many structures (large and small) where there is a choice between linked and contiguous reprentation.

I know that for insertion push_front() is faster for std::lists and push_back()s is faster for vectors. You can construct examples to illustrate that, but this example is not one of those.

don't store data unnecessarily,

keep data compact, and

access memory in a predictable manner.

And, yes, my recomendation is to use std::vector by default. More generally, use a contiguous representation unless there is a good reason not to. Like C, C++ is designed to do that by default.

Also, please don't make statements about performance without measurements. I have seen a case where changing a zero-to-two-element list to a zero-to-two-element vector made a factor-of-two difference to an algorithm. I didn't expect that. Nor did other experts looking at the code.

Much of the relative simplicity of Java is - like for most new languages - partly an illusion and partly a function of its incompleteness. As time passes, Java will grow significantly in size and complexity. It will double or triple in size and grow implementation-dependent extensions or libraries. That is the way every commercially successful language has developed. Just look at any language you consider successful on a large scale. I know of no exceptions, and there are good reasons for this phenomenon. [I wrote this before 2000; now (2012), the language part of the Java 7 specification is slightly longer in terms of number of pages than the ISO C++11 language specification.]

I have commented (negatively) about Java hype and ascribed much of Java's success to marketing. For example, see my HOPL-3 paper. Today (2010), the claims made about Java are more reality based and less gratuitously derogative about alternatives. This was not always so. For example, compare the original 1995 Java white paper with the versions you find on the web (sometimes labelled "the original Java whitepaper"); page 69 would be a good place to start.

Java isn't platform independent; it is a platform. Like Windows, it is a proprietary commercial platform. That is, you can write programs for Windows/Intel or Java/JVM, and in each case you are writing code for a platform owned by a single corporation and tweaked for the commercial benefit of that corporation. It has been pointed out that you can write programs in any language for the JVM and associated operating systems facilities. However, the JVM, etc., are heavily biased in favor of Java. It is nowhere near being a general reasonably language-neutral VM/OS.

Personally, I'll stick to reasonably portable C++ for most of the kind of work I think most about and use a variety of languages for the rest.

If you want to write exclusively for the .Net platform, C# isn't the worst alternative, but remember that C++ is a strongly supported - though less strongly hyped - alternative on that platform.

The CLI provides a set of interfaces (to system facilities) that are very different from traditional interfaces to operating system facilities and applications. In particular, these interfaces have semantics that cannot be completely or conveniently expressed in conventional programming languages. One way of describing CLI is as a (partial) "platform" or "virtual machine". It consists of a large set of language features (inheritance, methods, loop constructs, callback mechanisms, etc.), supporting a large set of foundation libraries (the BCL), plus an elaborate system of metadata. The CLI is sometimes described as "language neutral". However, a language that doesn't accept a large subset of these facilities cannot use even basic .Net facilities (or future Microsoft Windows facilities, assuming that Microsoft's plans don't change) and a language that cannot express all of these features cannot be used for the implementation of resources meant to be usable by other languages. Thus, CLI is "language neutral" only in the sense that every language must support all of the CLI features to be "first-class" on .Net.

I prefer a binding to be a few primitives, expressible as simple function calls and simple data structures in any language, possibly encapsulated in language-specific libraries. For the CLI, this can at best be done for consumers of CLI facilities only. A language used to produce CLI modules must be able to express all of the CLI facilities, including the metadata. Only a language that can do that can be considered a systems programming language on .Net. Thus, the Microsoft C++ team concluded that only build-in language facilities are acceptable to their customers. Their design reflects a view that accepts absolutely no restrictions on what part of CLI can be expressed in C++ with the C++/CLI extensions, absolutely no verbosity compared to other languages when using CLI facilities, and absolutely no overheads compared to other languages. They aim at preserving C++ as the dominant systems programming language for Windows.

As ever, I place a heavy emphasis on portability and recommend people to design applications so that access to system-specific facilities are through well-defined interfaces specified in ISO C++ (e.g., not to use C++/CLI directly). On Windows, this will sometimes be inconvenient compared with using C++/CLI facilities directly, but it's the only way to gain portability and a degree of vendor independence. Obviously, that arms-length approach to the CLI cannot be maintained if the purpose of a piece of code is to provide a CLI interface to be consumed by other code. Please note that I recognize the need for system-specific extensions and that Microsoft is not the only C++ vendor with such extensions, I just strongly prefer to deal with such extensions through a "thin interface" specified in ISO standard C++.

How to deal with system-specific extensions is inherently a difficult question. The Microsoft C++ team, especially Herb Sutter, has kept up an active dialog with (other) members of the ISO C++ standards committee so that the relationship between ISO C++ and its superset C++/CLI will eventually be worked out. We have a long record of constructive joint work in the ISO C++ committee. Also, to minimize confusion between ISO C++ and the C++/CLI extensions, Microsoft is now revising their Visual C++ documentation to try to clearly distinguish C++/CLI from ISO C++ (plain unqualified C++ means ISO C++). I hope others will follow that lead.

On the difficult and controversial question of what the CLI binding/extensions to C++ is to be called, I prefer C++/CLI as a shorthand for "The CLI extensions to ISO C++". Keeping C++ as part of the name reminds people what is the base language and will help keep C++ a proper subset of C++ with the C++/CLI extensions. The C/C++ compatibility problems demonstrate how important it is to keep that subset property.

Here are some documents related to C++/CLI:

Often a successful application/program have customers/users who prefer a variety of platforms. The set of desirable platforms change as the user population changes. Being tied to a single platform or single vendor, limits the application/program's potential use.

Obviously, complete platform independence is incompatible with the ability to use all platform specific facilities. However, you can often approximate platform independence for an application by accessing platform facilities through a "thin interface" representing the application's view of its environment as a library.

"Several reviewers asked me to compare C++ to other languages. This I have decided against doing. Thereby, I have reaffirmed a long-standing and strongly held view: Language comparisons are rarely meaningful and even less often fair. A good comparison of major programming languages requires more effort than most people are willing to spend, experience in a wide range of application areas, a rigid maintenance of a detached and impartial point of view, and a sense of fairness. I do not have the time, and as the designer of C++, my impartiality would never be fully credible.

I also worry about a phenomenon I have repeatedly observed in honest attempts at language comparisons. The authors try hard to be impartial, but are hopelessly biased by focusing on a single application, a single style of programming, or a single culture among programmers. Worse, when one language is significantly better known than others, a subtle shift in perspective occurs: Flaws in the well-known language are deemed minor and simple workarounds are presented, whereas similar flaws in other languages are deemed fundamental. Often, the workarounds commonly used in the less-well-known languages are simply unknown to the people doing the comparison or deemed unsatisfactory because they would be unworkable in the more familiar language.

Similarly, information about the well-known language tends to be completely up-to-date, whereas for the less-known language, the authors rely on several-year-old information. For languages that are worth comparing, a comparison of language X as defined three years ago vs. language Y as it appears in the latest experimental implementation is neither fair nor informative. Thus, I restrict my comments about languages other than C++ to generalities and to very specific comments."

That said, I consider C++ the best choice in programming language for a wide variety of people and applications.

When looking at a language comparison consider who wrote it, consider carefully if the descriptions are factual and fair, and also if the comparison criteria are themselves fair for all languages considered. This is not easy.

Well written C tends to be legal C++ also. For example, every example in Kernighan & Ritchie: "The C Programming Language (2nd Edition)" is also a C++ program.

Examples of C/C++ compatibility problems:

int main() { double sq2 = sqrt(2); /* Not C++: call undeclared function */ int s = sizeof('a'); /* silent difference: 1 in C++ sizeof(int) in C */ }

void f(); /* argument types not mentioned */ void g() { f(2); /* poor style C. Not C++ */ }

void* malloc(size_t); void f(int n) { int* p = malloc(n*sizeof(char)); /* not C++. In C++, allocate using `new' */ char c; void* pv = &c; int* pi = pv; /* implicit conversion of void* to int*. Not in C++ */ }

When converting from C to C++, beware that C++ has more keywords than C:

int class = 2; /* ok in C. Syntax error in C++ */ int virtual = 3; /* ok in C. Syntax error in C++ */

Please note that "C" in the paragraphs above refers to Classic C and C89. C++ is not a descendant of C99; C++ and C99 are siblings. C99 introduces several novel opportunities for C/C++ incompatibilities.

Please note that these papers were written in late 2001 and early 2002 when it was still possible to imagine coordinated action by the C and C++ standards committees leading to practical results by the end of the decade. This didn't happen.

At the time, I considered C the best systems programming language available. That was not as obvious then (1979) as it later became, but I had experts such as Dennis Ritchie, Steve Johnson, Sandy Fraser, Greg Chesson, Doug McIlroy, and Brian Kernighan down the corridor from whom I could learn and get feedback. Without their help and advice, and without C, C++ would have been stillborn.

Contrary to repeated rumors, I was never told that I had to use C; nor was I ever told not to use C. In fact, the first C++ manual grew from troff source of the C manual that Dennis gave me. Many new languages were designed at Bell labs; in "Research" at least, there were no rules enforcing language bigotry.

There is no language called "C/C++". The phrase is usually used by people who don't have a clue about programming (e.g. HR personnel and poor managers). Alternatively, it's used by people who simple do not know C++ (and often not C either). When used by programmers, it typically indicates a "C++ is C with a few useful and a lot of useless complicated features added" attitude. Often, that is the point of view of people who like to write their own strings and hash tables with little knowledge of the standard library beyond printf and memcpy. There are people who stick to a restricted subset of C++ for perfectly good reasons, but they (as far as I have noticed) are not the people who say "C/C++".

I use C/C++ only in phrases such as "C/C++ compatibility" and "C/C++ community".

The current definition of C++ The 2011 ISO C++ Standard described in The C++ Programming Language (4th Edition).

You can find a more complete timeline and more detailed explanations in The Design and Evolution of C++ and A History of C++: 1979-1991 and Evolving a language in and for the real world: C++ 19.

The specific tasks that caused me to start designing and implementing C++ (initially called "C with Classes") had to do with distributing operating system facilities across a network.

You can find more detailed explanations in The Design and Evolution of C++. See also A History of C++: 1979-1991 and Evolving a language in and for the real world: C++ 1991-2006.

At the time when I developed C++ - and before that when Ken Thompson and Dennis Ritchie developed Unix and C - AT&T was probably the worlds largest civilian user of (and consumer of) software tools. Then, we probably used a wider range of systems - from the tiniest embedded processors to the largest supercomputers and data-processing systems. That put a premium on systems that were applicable in many technical cultures and on many platforms. C and C++ were designed with such demands in mind.

Thus generality is essential, and proprietary features are seen as limiting the choice of platforms and vendors. As a consequence AT&T was and is a major supporter of formal standards (for example, ISO C and ISO C++).

Actually, AT&T made enough money on Cfront, my original C++ compiler, to pay for the development of C++ several times over.

Compiler vendors do not pay royalties to me or to AT&T for C++, and ISO standards are specifications intended for royalty-free use by everyone (once they have paid the ISO or a national standard committee for their copy of the standard). The individual compilers are owned by their respective vendors/suppliers.

"But someone from SCO claimed that they own C++"; is that not so? It's complete rubbish. I saw that interview. The SCO guy clearly had no clue what C++ was, referring to it as "the C++ languages". At most, SCO may own a 15-year old and seriously outdated version of Cfront - my original C++ compiler. I was careful not to patent or trademark anything to do with C++. That's one reason we write plain "C++" and not "C++(tm)". The C++ standard is unencumbered of patents - the committee carefully checked that also.

Chapter 1 of TC++PL: ``The name C++ (pronounced "see plus plus") was coined by Rick Mascitti in the summer of 1983. The name signifies the evolutionary nature of the changes from C; "++" is the C increment operator. The slightly shorter name "C+" is a syntax error; it has also been used as the name of an unrelated language. Connoisseurs of C semantics find C++ inferior to ++C. The language is not called D, because it is an extension of C, and it does not attempt to remedy problems by removing features. For yet another interpretation of the name C++, see the appendix of [Orwell,1949].''

The ``C'' in C++ has a long history. Naturally, it is the name of the language Dennis Ritchie designed. C's immediate ancestor was an interpreted descendant of BCPL called B designed by Ken Thompson. BCPL was designed and implemented by Martin Richards from Cambridge University while visiting MIT in the other Cambridge. BCPL in turn was Basic CPL, where CPL is the name of a rather large (for its time) and elegant programming language developed jointly by the universities of Cambridge and London. Before the London people joined the project "C" stood for Cambridge. Later, "C" officially stood for Combined. Unofficially, "C" stood for Christopher because Christopher Strachey was the main power behind CPL.''

Cfront was a traditional compiler that did complete syntax and semantic checking of the C++ source. For that, it had a complete parser, built symbol tables, and built a complete internal tree representation of each class, function, etc. It also did some source level optimization on its internal tree representation of C++ constructs before outputting C. The version that generated C, did not rely on C for any type checking. It simply used C as an assembler. The resulting code was uncompromisingly fast. For more information, see D&E.

Let's first be perfectly clear: No, I did not anticipate the run-away success of C++ and no, I did not foresee every technique used with C++ or every application of C++. Of course not!

However, statements like these are very misleading:

Bjarne doesn't understand C++!

Bjarne didn't anticipate RAII and deterministic destruction!

Bjarne didn't anticipate template-metaprogramming!

This FAQ was prompted by seeing these and several more of their ilk today.

I did outline the criteria for the design and implementation of C++. I did explicitly aim for generality: "I'm not interested in a language that can only do what I can imagine" and for efficiency "a facility must not just be useful, it must be affordable." I suggest that doubters read The Design and Evolution of C++ and my HOPL2 and HOPL3 papers (these are peer-reviewed papers). As for deterministic destruction, it was in "C with Classes" in the first week or two (1979). I held back the introduction of exceptions into C++ for half a year until I discovered RAII (1988). RAII is an integral and necessary part of the C++ exception mechanism.

I was very surprised when Jeremy Siek first showed me the compile-time if that later became std::conditional, but I had aimed for generalty (and gotten Turing completeness modulo translation limits). I opposed restrictions to C++ immediately when Erwin Unruh presented what is widely believed to be the first template metaprogram to the ISO Standards committee's evolution working group. To kill template-metaprogramming, all I would have had to do was to say nothing. Instead my comment was along the lines "Wow, that's neat! We mustn't compromise it. It might prove useful." Like all powerful ideas, template-metaprogramming can be misused and overused, but that does not imply that the fundamental idea of compile-time computation is bad. And like all powerfuls ideas, the implications and techniques emerged over time with contributions from many individuals.

There is more to scolarship than a look at the wikipedia, a quick Google-search, and a couple of blog posts. There is more to invention than giving a simple list of implications. Fundamental principles and design guidelines are essential. My part of the C++ design opened the possibility for many to contribute, and if you look at my writings and postings, you see that I try hard to give credit (e.g., see the reference sections of my C++11 FAQ) or the history sections of my books.

And no, I'm not a walking C++ dictionary. I do not keep every technical detail in my head at all times. If I did that, I would be a much poorer programmer. I do keep the main points straight in my head most of the time, and I do know where to find the details when I need them. For example:

Also, C++ supports programming techniques that allows memory management to be safe and implicit without a garbage collector. I consider garbage collection a last choice and an imperfect way of handling for resource management. That does not mean that it is never useful, just hat there are better approaches in many situations.

C++11 offers a GC ABI.

I don't like garbage. I don't like littering. My ideal is to eliminate the need for a garbage colletor by not producting any garbage. That is now possible. Tools supporting and enforcing the programming techniques that achieves that are being produced. For an overview, see A brief introduction to C++'s model for type- and resource-safety..

Note that providing a GUI is both a technical and political problem. There are lots of GUIs with lots of users, and generally they wouldn't like some other GUI to be declared standard. Anyway, the standards committee do not have the resources to build a new and better GUI.

One simple thing that confuses many discussions of language use/popularity is the distinction between relative and absolute measures. For example, I say (in 2011) that C++ use is growing when I see user population grow by 200,000 programmers from 3.1M to 3.3M. However, somebody else may claim that "C++ is dying" because it's "popularity" has dropped from 16 percent to 11 percent of the total number of programmers. Both claims could be simultaneously true as the number of programmers continues to grow and especially as what is considered to be programming continues to change. I think that C++ is more than holding its own in its traditional core domains, such as infrastructure, systems programming, embedded systems, and applications with serious time and/or space and/or power consumption constraints. See also my DevX interview.

The first ISO C++ standard was ratified in 1998. The next version C++11, is complete and shipping. You can find papers describing C++11 on my publications page and all documents relating to the new standard on the ISO C++ committee's home pages. My HOPL-iii paper on the last 15 years of C++ evolution may the best explanation of what is being done and why. A recent interview contains lists of new language features and standard libraries.

When considering the evolution of C++, it is worth remembering that the aim is not to add the largest number of new features, but to improve C++ for its key application domains, including systems programming and library building, without breaking older code (there are billions of lines of C++ "out there").

Since 1987 or so, the focus of development the C++ language and its associated programming styles have been the use of templates, static polymorphism, generic programming, and multiparadigm programming. This is way beyond the scope of the much-hyped proprietary languages. Another key difference is that C++ supports user-defined types to the same extent as built-in types. This - especially in combination with the use of templates, constructors, and destructors - enables the C++ programmer to use programming and design techniques that (IMO) are more advanced than what is supported in the languages with which C++ is most often compared; e.g. see RAII.

Standard C++ and the design and programming styles it supports owe a debt to the functional languages, especially to ML. Early variants of ML's type deduction mechanisms were (together with much else) part of the inspiration of templates. Some of the more effective functional programming techniques were part of the inspiration of the STL and the use of function objects in C++. On the other hand, the functional community missed the boat with object-oriented programming, and few of the languages and tools from that community benefited from the maturing experience of large-scale industrial use.

Clearly, I don't think that garbage collection is the sole defining characteristic of "advanced" in the context of programming languages. In particular, note that C++ provides support for effective and efficient memory management techniques that can eliminate resource leaks without the use of a garbage collector. If you disagree, you can just start using a garbage collector for C++; there are good ones available.

void draw_all(vector<Shape*>& vs) // draw each element of a standard vector { for_each(vs.begin(),vs.end(),[](Shape* p){ p->draw(); }); }

template<class C> void draw_all(C& cs) // draw each element of a standard container { for_each(cs.begin(),cs.end(),[](Shape* p){ p->draw(); }); }

Jim Coplien's book "Multiparadigm Design for C++" (Addison Wesley, 1998) explores the use of multiple paradigms in the context of design and design methods.

We need a better -- more descriptive -- term to replace ``multi-paradigm.''

The C++ standard is 1151 pages; that includes 430 pages of language definition and 770 pages of standard-library description. The size of the language definition is within 5% of the language descriptions of Java and C# (measured by page count). Similarly, TC++PL is 1360 pages; of those 750 of those are devoted to language facilities and programming techniques; the rest discuss libraries, etc.

C++ directly supports (i.e., in the language) what some other languages support through libraries, so the language part will be relatively larger. On the other hand, if you want to write a "typical modern application", you need to consider operating system interfaces, GUI, databases, web interfaces, etc. the sum of language features, libraries, and programming conventions and standards that you must become familiar with dwarf the programming language. Here, C++'s size can be an advantage as far as it better supports good libraries.

Finally, the days where a novice programmer can know all of a language are gone, at least for the languages in widespread industrial use. Few people know "all of C" or "all of Java" either and none of those are novices. It follows that nobody should have to apologize for the fact that novices do not know all of C++. What you must do - in any language - is to pick a subset, get working writing code, and gradually learn more of the language, its libraries, and its tools. For my suggestion on how beginners can approach C++, see Programming: Principles and Practice using C++.

For a discussion of how embedded systems implementers can address performance issues using Standard C++ (better than by using dialects) see the ISO C++ committee's report on performance. To the best of my knowledge EC++ is dead (2004), and if it isn't it ought to be.

For a look at how ISO C++ can be used for serious embedded systems programming, see the JSF air vehicle C++ coding standards.

That said, writing C-style programs in C++ is for most applications not an optimal use of C++. To be a really effective C++ programmer, you must use the abstraction mechanisms and the type system in a way that fits reasonably with their intent. Trying to ignore or defeat the C++ type system is a most frustrating experience.

Writing Java-style code in C++ can be as frustrating and sub-optimal as writing C-style code in C++.

For a more detailed discussion see any of my overview or style papers from my bibliography. In particular, see my OOPSLA paper "Why C++ isn't just an Object-Oriented Programming Language".

"Within C++, there is a much smaller and cleaner language struggling to get out". Yes, that quote can be found on page 207 of The Design and Evolution of C++. And no, that smaller and cleaner language is not Java or C#. The quote occurs in a section entitled "Beyond Files and Syntax". I was pointing out that the C++ semantics is much cleaner than its syntax. I was thinking of programming styles, libraries and programming environments that emphasized the cleaner and more effective practices over archaic uses focused on the low-level aspects of C.

"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone". I said that after a frustrating attempt to use a "feature-rich" telephone sometime around 1990. I'm sure the sentiment wasn't original, and probably not even the overall phrasing; someone must have thought of that before me.

"There are only two kinds of languages: the ones people complain about and the ones nobody uses". Yes. Again, I very much doubt that the sentiment is original. Of course, all "there are only two" quotes have to be taken with a grain of salt.

"Proof by analogy is fraud". Yes; page 692 of TC++PL. A good analogy is an excellent way of illustrating an idea, but far too often such analogies are not accompanied by solid reasoning, data, etc.

"People who think they know everything really annoy those of us who know we don't". Yes.

"C++ Is my favorite garbage collected language because it generates so little garbage". Yes; see Why doesn't C++ have garbage collection? and How do I deal with memory leaks.

"If you think it's simple, then you have misunderstood the problem". Yes, but no, I don't recall which question elicited that answer.

"There are more useful systems developed in languages deemed awful than in languages praised for being beautiful--many more". Yes, in MIT Technology Review interview and elsewhere. There, I also said:

"I think we should look for elegance in the applications built, rather than in the languages themselves" . I should have said "more than" rather than "rather than".

. I should have said "more than" rather than "rather than". "To use C++ well, you have to understand design and programming technique" .

. "C++ is designed to allow you to express ideas, but if you don't have ideas or don't have any clue about how to express them, C++ doesn't offer much help".

"The <random> library is what a random library wants to be when it grows up. As a result, beginners use rand()". Yes. In the CppCon 2017 opening keynote: The Learning and Teaching Modern C++.

"The fact that 'goto' can do anything is exactly why we don't use it". Yes. In the CppCon 2017 opening keynote: The Learning and Teaching Modern C++. I did/do point out that 'goto' is excellent in machine generated code.

"If the comment and code disagree, both are probably wrong". Yes, quoting Norm Schryer, I think. In the CppCon 2017 opening keynote: The Learning and Teaching Modern C++.

"Teach for the future; you have to live in it". Yes. In the CppCon 2017 opening keynote: The Learning and Teaching Modern C++. Also, in other contexts: Build for the future; you have to live in it. An organization that treats its programmers as morons will soon have programmers that are willing and able to act like morons only. Yes. TC++PL3.

"Don't be clever". Yes. In the CppCon 2017 opening keynote: The Learning and Teaching Modern C++. The accompagnying slide says "Don't be (too) clever" but I can't promounce parentheses :-). My point was to discourage overly clever code because "clever code" is hard to write, easy to get wrong, harder to maintain, and often no faster than simpler alternatives because it can be hard to optimize.

Always be suspicious of 'of course': 'of course' is not a reason. Yes.

Beware of 'obvious'; it often means "I haven't thought carefully about it". Yes.

"Far too often, 'computer science' is a form of math envy". Yes, but please don't forget that "Far too often." The quote comes from a context where I'm worrying about insufficient attention to data (empiricism) and insufficient attention to the connection to computing. It is not a frontal assault on the notion that computer science can be science (e.g., see Knuth on algorithms and the analysis of algorithms; that's science and it is not any other science). And, no, I'm not going to give concrete examples or names.

"Far too often, 'software engineering' is neither engineering nor about software". Yes, but please don't forget that "Far too often." The quote comes from a context where I'm worrying about insufficient attention to data (empiricism) and insufficient attention to the connection to code. I'm worried that the realities of having to deliver useful and maintainable code can be drowned in processes, corporate standards, and marketing studies; that software development sometimes is controlled by people who couldn't recognize good code if it jumped up and punched them on the nose, and are proud of that. And, no, I'm not going to give concrete examples or names. When practiced well, software development is a worthy engineering discipline, delivering results that compares well with those of older engineering disciplines.

"When (not if) automatic garbage collection becomes part of C++, it will be optional". Yes in a a 2000 interview with /.. Since C++11, C++ as a garbage collection interface, but it is not used much. Most people who want resource safety (no leaks) and memory safety (no memoty corruption) use smart pointers and RAII.

"It's easy to win forgiveness for being wrong; being right is what gets you into real trouble". Yes.

"Any problem in computer science can be solved with another layer of indirection", known as the 1st law of computing. The full quote is "Any problem in computer science can be solved with another layer of indirection, except of course for the problem of too many indirections". Yes, I said that quoting (my PhD Thesis advisor) David J. Wheeler. Please don't misattribute it to me.

"I have yet to see a program that can be written better in C than in C++". Yes, many times, including my electronic design interview. I don't believe such a program could exist. By ``better'' I mean smaller, more efficient, or more maintainable. If nothing else, you can write the program in C style benefiting from C++'s stronger type checking and better notational support, but most programs can benefit from C++'s support for generic and object-oriented programming without compromising size or performance. Sticking to the C-like subset of C++ is most often counter-productive.

"Test early and often". Yes, often, including Chapter 22 of Programming: Principles and Practice using C++.

"Space is time". Yes, referring to the fact that compact data is faster to traverse than scattered data (e.g., a traversing a vector can be dramatically faster than traversing a linked list) and faster to input and output.

"The only thing that grows faster than computer performance is human expectation". Yes, often since the late 1980s. It was my standard answer to suggestions that we really didn't need to work on making software efficient any more because hardware is getting faster. Of course, today, single core performance hasn't improved for years.

"friendship is neither inherited nor transitive". Yes. It's a C++ language rule from the earliest days.

"Only half of the C++ community is above average". Yes, in a WG21 evening session discussing future directions. The point was to remind the C++ standards committee members that they should design for the C++ community at large, rather than just for experts like themselves.

"Nobody should call themselves a professional if they only know one language". Meaning professional as a software developer or direct manager of software developers. Yes. Many times.

"The most important single aspect of software development is to be clear about what you are trying to build". Yes, in TC++PL2 and TC++PL3.

"Our civilization runs on software". Yes, stating the obvious. It's a plea for more reliable and maintainable code. If our computerized systems fail badly, many will starve.

"To many managers, getting rid of the arrogant, undisciplined, over-paid, technology-obsessed, improperly-dressed etc. programmers would appear to be a significant added benefit". Yes, in TC++PL2 and TC++PL3.

"To optimize old code, first get rid of the fancy stuff". Yes, the point being that new C++ features and better optimizers often make cleaner modern code run faster than elaborately hand-optimized code.

"When was the last time you checked the return value of printf?" Yes, the point being that rare errors are often not caught, leading to surprising crashes. This is an argument for using exceptions: they cannot be ignored.

"The problem with many professors is that their previous occupation was student". Yes. You need experience beyond book learning to teach well.

"Design and programming are human activities; forget that and all is lost". TC++PL3.

"If you give people the choice of writing good code or fast code, there's something wrong. Good code should be fast". CppCon 2018 keynote.

"I hate to choose between elegance and efficiency". Yes. Often.

"Someone who claims to have a perfect programming language is either a salesman or a fool, or both". Yes. Often.

"If you never fail, your aren't trying hard enough". Yes.

"Absolute certainty is a terribly thing". Yes. In the context of programming, not Mathematics.

"Every new powerful feature will be overused and misused". Yes. It's an observation -- a statement of fact. After a while and some experimentation, good programmers find what works in real-world development and what's just overenthusiasm.

"Cut until there is nothing left to cut and all there is left is principled and fundamental". Yes. In http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1962r0.pdf.

"We are defining a language for decades of use. A bit of humility is necessary". Yes. In http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1962r0.pdf.

"My best tool for efficiency and performance is abstraction". Yes. In my interview with Lax Friedman.

Nothing significant is uncontroversial. Yes, but of course just being controversial doesn't make somthing significant.

"All successful languages are grown and not merely designed from first principles". Yes. When it looks as if it is not, there is a previous incarnation of the idea and as its use grows, the language evolves to meet needs.

It seems that often I'm the only one around who doesn't have a firm opinion about what C++ is". Yes. In the context context of oversimplification vs. carefule consideration.

Without philosophy language design becomes hacking. Yes. Variaous talks.

My ideal of program design is to represent the concepts of the application domain directly in code. That way, if you understand the application domain, you understand the code and vice versa. Yes. Various talks.

Of course not. Read the real IEEE interview.

C++ was initially designed and implemented as a set of general facilities addressing some specific problems that I and my colleagues faced. The generality - and efficiency - of the facilities provided turned out to serve much wider needs than I had anticipated. The emphasis on general facilities - as opposed to the provision of specific solutions to specific problems - has remained with C++ and has served its community well as the specific problems facing the community have changed over the years.

PS. I work for Morgan Stanley, not J.P. Morgan. Morgan Stanley is a fairly heavily-regulated bank, rather than a generic ``financial institution,'' and IMO one of the most ethically-run financial institutions.

PPS. You simply cannot run a modern society without banks.

PS. Texas A&M University != University of Texas.

Seriously, I'm looking for fundamental ways of improving the tools and techniques we use to build large real-world systems. One part of my work is C++11.

Look at my papers for HOPL-2 and HOPL-3; HOPL stands for "History Of Programming Languages", the premier conference on that subject, sponsored by the ACM. These are heavily peer-reviewed papers. For even more information see my book The Design and Evolution of C++ and the Preface to the 2006 Japanese translation of D&E which brings the information up to 2006. Also, many of my interviews touch upon the issues of background, design, and history of C++.

C++ is low-level(?)

C++ is too slow for low-level work(?)

C++ is useful only if you write truly object-oriented code(?)

Modern C++ is all generic programming and template metaprogramming(?)

C++ is designed by Microsoft(?)

The Boost libraries have tests suites, have documentation, have been tested on multiple systems, and are peer reviewed.

I have two problems with Boost, though, which I hope will be dealt with eventually:

It is too hard to download and use just one Boost library; the libraries seem overly coupled making it hard to pick and choose.

Some of the libraries are too clever for my taste. Sometimes, generality and simplicity coincide; in Boost, the balance is IMO too often so far towards generality that novices and average users are lost.

Like all powerful techniques they are easily overused. Personally, I tend to use templates primarily for generic programming (e.g., defining containers and algorithms over containers) and for templates that generate fairly obvious code based on template arguments (e.g., generating buffers and register access code); that's sometimes called generative programming. Be careful about the complexity of the templates you write or use; it is easy to get overenthusiastic and write template code that is too clever to be useful as maintainable production code.

If you do not like functional programming styles, you might find template metaprograms hard to understand. If you do like functional programming, you may find the template version a bit primitive, but remember these templates are executed at compile-time.

C++'s support for metaprogramming is improving. Concepts will dramatically simplify generic programming and make much of the scaffolding for template metaprogramming redundant. Furthermore if what you want to generate is a value (say and integer value), constexpr functions are far easier to use (and compile faster).