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).
Analyze C++ code semantics through IR code
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.
A brief discussion on fork/vfork
In *UNIX, multi-process programming can be implemented using fork/vfork. Here is a summary of the relevant knowledge.
Programming skills and concepts in C/C++
Some examples in C++ that can be confusing or have peculiar usages are recorded.
Main-function prototype verification and program termination behavior
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.
Incompatibilities between C and 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.
The difference between declaration and define in C++
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.
C++ object construction and destruction order
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.
C++ overload and override
In C++, overload
and override
are not related, but they are easily confused due to the similarity of the terms.
Samba Configuration on Linux
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.