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 »

fork/vfork浅谈

In *UNIX, multi-process programming can be implemented using fork/vfork. Here is a summary of the relevant knowledge.

Read more »

main原型考证及程序终止行为

In C and C++, there are many versions of the main function prototype that circulate, and different books present different ways of writing it. Today, I will explore what constitutes “standard behavior” from the perspectives of several standards (C89/99/11 and C++98/03/11/14) and what happens after the main function returns.

Read more »

C和C++之间的不兼容

Previously, it has been mentioned several times that C and C++ are not the same language. Even the part inherited from C in C++ has significant differences from ISO C. I will gradually compile some of their incompatible features here.

Read more »

C++中declaration与define的区别

Many C++ books do not clearly state the difference between declaration and definition, or they only mention the need to support separate compilation, indicating that using the extern specifier is a declaration, while without it is a definition. In fact, I think the C++ standard describes the difference between declaration and definition more clearly.

Read more »

对象的构造和析构顺序

Through a CppQuiz question to describe the order of construction and destruction of C++ objects in the context of inheritance according to the C++14 standard, as well as throwing exceptions during object construction/destruction.

Read more »

重载(overload)和重写(override)

In C++, overload and override are not related, but they are easily confused due to the similarity of the terms.

Read more »

Linux上的Samba配置

Through Samba, we can mount folders from Linux to Windows. After deploying Samba on a Linux virtual machine, I can use the remote compilation plugin I wrote a few days ago (sublimeRemoteCompile) to write code on Windows! It’s quite enjoyable. Today, I will briefly record how to configure Samba sharing on the server for friends with similar needs.

Read more »