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 »

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 »