1. The difference between a pointer and a reference
1. The pointer is a variable that stores an address pointing to a storage unit in memory and requires a separate allocation of memory space. Refer to aliases that are equivalent to variables and do not need to allocate space separately
2. References must be initialized, pointers can not be initialized first
3. The pointer can be set to the const type, and the reference cannot be const
4. As a formal parameter, the reference in the function body can directly modify the original value, the pointer is a copy of the original variable
5. Monocular operator + +, acting on the reference int a=1;int b=&a; b++ equivalent to a++;
Acting on the pointer int a = 1; int *b=&a; b++ only indicates that the pointer address is increased and a has not changed
6. Pointers can have multiple levels, with only one reference.
7. After the pointer definition can be modified to execute other storage units, reference definitions cannot be modified.
After the 8.sizeof operator is processed, the calculated pointer represents the size of the pointer: 32 is 4 for the system, and the computed reference gets the size of the corresponding type: the char-type reference is 1.
2.volatile action (CPU caching mechanism), what are the instances?
When compiling optimizations, in order to optimize execution speed, some variables use copies that are saved in registers when they are called. Variables that use volatile modifiers indicate that the variable will be accidentally changed, and each use should be carefully read from memory to the original value
Examples of > phenomena:
1. Contents of the Status register
2. Non-automatic variables accessed in the Interrupt service program
3. Shared variables for multi-threaded threads
3.static Const usage Description (parameters and variables).
>const usage:
1. Must be initialized at the time of definition
2. Variables that are not modified by the program
3. A modified parameter indicates that the formal parameter cannot be modified in the calling function body
4. Several situations when modifying pointers:
The const int *a pointer points to a constant shape number
int *const A pointer is a constant pointer
const int *a const A constant pointer to the execution of a constant shaping data
Static usage:
1.static variables are defined only once, avoiding the problem of multiple definitions
The 2.static variable is initialized to 0 by default and is stored in the static store BSS segment. Variables are placed in the program's global store, so that the original assignment can be maintained at the next call. This is the difference between a stack variable and a heap variable.
3. Variables tell the compiler with static that they are visible only within the scope of the variable. This is the difference between it and the global variable.
4. The static variable condition must be used in the function: for example, when the return value of a function is a pointer type, it must be the address of the static local variable as the return value, and if it is the auto type, it is returned as the wrong pointer.
4. The effect of inline functions differs from macro definitions. Why the inline function is defined in the header file and is added to the static
The function of a macro is the basic character substitution, which is performed during the compile phase. The use of inline functions saves call and RET and function functions in order to save time on function calls
1. Inline functions can be debugged at run time, while macro definitions are not possible;
2. The compiler will perform security checks on the parameter types of the inline function or automatic type conversions (same as normal functions), but the macro definition will not;
3. The inline function can access the class's member variables, and the macro definition cannot;
4. Declare a member function that is also defined in a class and automatically convert to an inline function.
Why the > inline function is defined in the header file and is added to the static
The inline keyword is actually only recommended inline and is not mandatory inline, GCC O0 optimization is not inline, even if the function is O2 or more, if it is assigned as a function pointer, then he will not inline, also must produce a function entity to obtain the function address.
The only inline function in the test C file, even if the OS optimization is not inline, because there is no static, compiled to recognize that he is a global, so like a normal function compiled, this c file is the same through the BL inline_func such a way to call, unlike what others say on the Internet, this c will be inline, Other c files are passed the BL inline_func mode. After adding static, it is inline. (OS optimization level test)
Therefore, it is important to add static when using inline in the header file, otherwise when inline is not inline, it is defined in the header file as the normal function, and is redefined when multiple C files are contained. So the addition of the static code is high robustness, if all inline with the actual effect is the same. (GCC verifies that only inline functions are defined in O0 level includes.h, compilation fails, OS compilation succeeds)
Although you know that you want to add static when using the inline function in the header file, why do you define the function in the header file?
Some simple encapsulation interface functions, such as open () {Vfs_open ()}, are just to encapsulate an interface, we do not want to consume the time of a function call, the solution is a macro, but as an interface, the macro is not clear enough. That selects inline, but if you write in the C file
Main.c
inline void open (void)
{Vfs_open ();}
Header file
PlusDeclaration, external to use is not inline, because the compiler has a principle, the C file is compiled by each obj, each c file is compiled independently, the C file used by the external function is compiled to reserve a symbol, Only when all obj generated links are given to these symbolic addresses (the link script determines the address), so the other C files are compiled to see only the declaration of the function and cannot know her entity, like a normal function through the BL a function address, and so on when the link is filled in the address, he can not do inline expansion. So the inline must represent the entity in every C file that uses it, and that's only
in the header file, so the function implementation of this kind of hope to use globally and increase efficiency is added in the header file.
StaticInline
5. Static memory allocation and dynamic memory allocation differences.
6. The difference between enumerations and # define
7. Memory alignment rules.
8. The difference between dynamically allocated objects and statically assigned objects.
9. What are the memory overflow factors?
The difference between 10.new/delet and Malloc/free.
11. How the template is implemented, the role of the template
12. What are the multi-threaded locking mechanisms?
13. Spin lock and mutual exclusion lock difference.
14. Inter-process communication and inter-threading communication methods
15.
Linux C Basic Knowledge collation