C++技术书籍书评汇总

Separate an article; previously scattered book reviews were scattered in notes and tweets, and not collected in one place, making indexing inconvenient. In the future, after reading technical books, I will write some comments and put them all here. Since the subjects of the reviews are technical books, mere phrases cannot describe all the technical details. The intent of this article is not “technical notes,” but rather “book reviews,” so I won’t delve too deeply into the technical details described in the books. Instead, I will share my own reading experiences and tips as an ordinary reader. If I express any opinions about certain books, they are my personal evaluations of the books with no intention of demeaning the authors.

Read more »

特殊成员函数的隐式声明及其标准行为

In C++ programming, one of the most frustrating things is that the compiler does too much behind the backs of programmers. This article compiles various situations and actual behaviors of six special member functions: default constructor, copy/move constructor, copy/move assignment operator, and destructor, as outlined in the C++ Standard ([ISO/IEC 14882:2014]). It can serve as supplementary material for “Inside The C++ Object Model,” enhancing the understanding of compiler implementations through standard descriptions.

Additionally, “Inside The C++ Object Model” mainly describes things from the perspective of “compiler implementation,” but from the “C++ standard” perspective, many things in the book are dependent on compiler implementation. For example, the virtual function table; the standard does not specify how the compiler should implement polymorphic behavior, thus it cannot describe details about the virtual function table.

Moreover, many ambiguous interpretations related to the behavior of “compiler-generated” can be addressed here, which is part of the joy of reading the C++ standard—regardless of whether it’s good or bad, the standard specifications cannot be wrong; all implementations that do not adhere to the standard descriptions are unstandard.

Read more »

C++中指向类成员的指针并非指针

“Pointers to members” is a feature in C++ that is not commonly used. However, the use of the term “pointer” is somewhat inaccurate here, as they do not contain an address, and their behavior is not like pointers. This article will analyze how “pointers to class members” are implemented in clang through LLVM-IR, alongside some definitions from the C++14 standard and related LLVM-IR syntax.

Read more »

为什么需要extern "C"?

In the previous article (C/C++ Compilation Model Analysis), the reasons and methods for compilation and linking in C and C++ were introduced. Following the issues discussed in the previous article, this article starts with extern "C" to analyze the differences and causes in the compilation and linking models of C and C++, focusing primarily on function overload, function signatures, and name mangling.

Read more »

C/C++编译和链接模型分析

C and C++ both use separate compilation to support a multi-source file modular mechanism, but why this is done and how it is achieved is a topic worth exploring. This article is not about the syntactic rules that create different linking in C and C++, but rather analyzes how C/C++ compilers implement the compilation and linking model.

Read more »

I looked at the usage of Array of length zero in C, and I feel quite inspired. However, from a standard perspective (as opposed to compiler extensions), this feature only exists in the C language (after C99) and does not exist in C++. Let’s dig into it.

Read more »

虚拟存储器的缺页异常分析

Consider this question: Is it possible to pass the address of an object from process A to process B (where there is no relationship between A and B) through a pipe (fifo), and thus access the object of process A from process B?

Read more »

STL容器的迭代器失效

The size of a container refers to the number of elements in the container; the capacity of a container refers to the number of elements that the container can hold before reallocating more memory. When resizing or changing capacity, the elements may move to new storage locations. This means that iterators (as well as pointers or references) pointing to the elements may become invalid (i.e., point to the old element locations).
Iterators pointing to elements of associative containers only become invalid when the pointed element is removed from the container (erased). In contrast, iterators pointing to elements of sequential containers may become invalid when memory is reallocated (resize()/reverse() or push_back()) or when the pointed element moves within the container (such as by performing an erase() or insert() at its previous position).

Read more »

通过IR代码来分析C++代码语义

IR code is the Intermediate Code generated by LLVM. By analyzing the IR code, we can understand how the compiler parses and executes the code we write, making the analysis of code semantics clearer. The syntax and semantics of the IR code can be referenced in the LLVM Language Reference Manual.

Read more »