读TC++PL、C++Primer和ISO C++

Spent a month reading TC++PL4E. Since I had previously read C++ Primer and understood most of the C++ syntax, the reading speed was quite fast. However, by reading alongside the C++ standard, I discovered many things in C++ that I previously didn’t know. From the perspective of the standard and the father of C++, C++ is indeed comprehensive enough. Thus, I’ll compare C++ Primer, TC++PL4E, and the ISO C++ documentation.

C++ Primer 5th

C++ Primer 5th has “Primer” in its title, but I actually don’t think this is a beginner-level C++ book. I find the chapter arrangement a bit odd; the content introduced earlier only gets explained later. Nevertheless, it is indeed a very good C++ book. If you have a background in C or already have some understanding of C++, this book is a great choice for learning C++ comprehensively and with some depth. It explains the commonly used C++ features very clearly, and the code examples are easy to understand, covering most of the essential knowledge points of C++ in a comprehensive and in-depth manner.

TC++PL 4th

TC++PL (The C++ Programming Language Fourth Edition) is also not a zero-basis C++ book; I think the requirements for reading this one are slightly higher than C++ Primer. This book is written by the father of C++, Bjarne Stroustrup, and comprehensively covers all features of C++. In terms of C++ language features, this book is more comprehensive than C++ Primer (it includes detailed discussions on ADL/POD, etc.), but the length of each chapter and its summaries is shorter (concise). For more in-depth or detailed information, you still need to refer to other documents. TC++PL is more like a manual or an outline, suitable for quick reference. The example code is quite concise, but some knowledge points are not analyzed as deeply as in C++ Primer; for instance, the section on lambda/classes is written more comprehensively in C++ Primer. Perhaps the father of C++ wanted to treat all parts of C++ equally, as he mentions in the preface the swelling of content due to page limits (including the standard library part, which is over a thousand pages in Chinese and more than thirteen hundred in English), making it a hefty book that inevitably involves some trade-offs.

If you don’t have enough time to read this book thoroughly, a small trick is: Bjarne provides some coding suggestions at the end of each chapter. You can read these suggestions and think about why they are made. If you can figure out why when you see the suggestion, it means you are familiar with that part of the knowledge. If you see a suggestion and don’t know why it’s suggested, assume you are not familiar with that part, and look into it with purpose. This approach can greatly improve reading efficiency, though the downside is that it may lack a systematic view.

ISO C++(2014)

What is referred to as ISO C++ here is based on ISO/IEC 14882:2014(E), which is C++14.

Reading the standard and studying language books provide two different experiences. In books, you can see the author’s personal insights. Many masters (Bjarne Stroustrup/Stanley B. Lippman) offer brilliant perspectives, but there are also instances where misunderstandings arise during the transmission or comprehension of knowledge (you notice this when reading others’ blogs…). Thus, more authoritative materials are needed to back up information, and for language, the standard document is the most authoritative.

The standard document hardly discusses specific syntax usages; it focuses on what semantics the language syntax should implement. In this context, the language semantics implemented by a compiler should strictly follow the standard requirements, and any compiler conflicting with the standard documentation is considered non-standard. Thus, we can determine the adherence of a compiler’s implementation to the standard based on this.

You can check the compliance of various compilers with the standard here.

From the perspective of learning the language, studying language standards allows us to understand C++ more deeply. The requirements laid out in the standard document are clear and unambiguous; the stipulations of the standard are the truth (regardless of quality). However, many specific implementations of language features are not specified, which can lead to confusion due to the different implementations of language features among compilers (for instance, vptr). When we need to employ certain tricks, it can cause a lot of trouble, so it’s best to avoid using those tricks unless necessary. Moreover, the most important thing about learning C++ is to remember not to rely on just one compiler, as its implementation might also be non-standard (like MSVC). Hence, while writing code, it’s advisable to test the code with multiple compilers and refer to the standard documentation for any ambiguous areas.

Postscript

All three resources have their merits; however, in terms of overall quality, depth, and value, I recommend reading C++ Primer in depth for a more comprehensive understanding of C++. If time permits, purchase TC++PL to quickly skim through and use it as a reference manual, ideally in conjunction with the standard documentation (mainly used to resolve ambiguities).

C++ Primer and TC++PL can be interchangeable, but since their purposes differ (at least that’s my view), I suggest reading both if time allows. If time is tight, you can read either C++ Primer or TC++PL, but make sure to buy the fifth edition of C++ Primer and the fourth edition of TC++PL. Both editions are based on the C++11 standard, which is quite different from the previous standard (C++03).

The suggested reading order is (<=> indicates interchangeability, = indicates simultaneous reading and mutual reference):

(C++ Primer<=>TC++PL)=ISO C++

For an overview of the changes between C++11/14/17, here are Bjarne Stroustrup’s PPT slides from the 2016 C++ and Systems Software Conference:



The article is finished. If you have any questions, please comment and communicate.

Scan the QR code on WeChat and follow me.

Title:读TC++PL、C++Primer和ISO C++
Author:LIPENGZHA
Publish Date:2016/12/06 23:16
World Count:5k Words
Link:https://en.imzlp.com/posts/4367/
License: CC BY-NC-SA 4.0
Reprinting of the full article is prohibited.
Your donation will encourage me to keep creating!