复习c/c++中关于指针对内存操作,指针是c的灵魂。偶然发现mit 6-088课程,非常适合这个主题。自学之。
1.什么时候使用指针
①.堆上分配内存时
②.当给被调用函数传参时,希望其改变其值时
③.为了效率--避免拷贝数据结构
2 gcc编译的过程
Preprocessor
Translation of # directives.
•
Translates all macros (#DEFINE’s) into inline C code.
•
Takes #include files and inserts them into the code.
•
Get redefinition error if structs etc. are defined more than once!
•
Use #ifndef directive to define things only if they have not been defined.
#ifndef HEADER NAME
#define HEADER NAME
/∗ Header code here
#endif
Parsing and translation
Translates to assembly, performing optimizations.
Assembler
Translates assembly to machine instructions.
Linking
•
Static. For each function called by the program, the assembly to that function is included directly in the executable, allowing function calls to directly address code.
•
Dynamic. Function calls call a Procedure Linkage Table, which contains the proper addresses of the mapped memory