Questions and Answers (winter operations 1)

1.C disadvantage Language
<1> is determined on the size of the float, because some of the fractional binary conversion results can not be accurately stored correct value, then the judgment result of the error may exist. At this time we believe it is necessary to set up a precision to determine if the absolute value of the difference between the two numbers, then in addition to accuracy, we can be seen as two equal numbers. Similar examples appear in the C language DS dichotomy solving a quartic equation.
<2> infinite loop while as the value range caused. Similar ranges such as char -128127, while (c <151) caused by an infinite loop; int i = 0; while (i <100) {i-;}, which is a pseudo-infinite loop, the int range -21474836482147483647, when i is reduced from -2147483648, the decrement becomes 2147483647 then the cycle is completed. There are similar natural number overflow problem.
<3> array can not function properly. For example, int arr [100000] requires a global open outside the main function and array bounds is not recognized properly.
<4> C programming language oriented process. Process-oriented analysis is a required step to solve the problem, then use the function to implement these steps, step by step, when used in a call to a turn on it. Backgammon e.g., idea for the design process is the first step of analysis of the problem: 1, to start the game, 2, go sunspots, 3, drawing pictures, 4, determines winning or losing, 5, turn albino, 6, drawing pictures, 7, is determined winning or losing, 8, returns to step 2,9, and finally outputs the result. Each step of the above method to achieve different, so to expand the terms, C language is weak.
2.C language / C ++ compiler process
1. Pre-treatment (Preprocessing These),
2. Compiler (Compilation),
3. compilation (Assemble),
4. link (Linking).
1. Pre-treatment (Preprocessing These)
pretreatment for all of the header files and macros #include replaced into its real content, obtained after pre-treatment is still a text file, but the file size will be much larger. Pretreatment gcc preprocessor cpp is done, you can test.c command by
pretreatment:
gcc test.c -o -E -I./inc test.i
or directly invoking cpp command
cpp test. c -I./inc -o test.i
The above command -E is for the compiler to exit after pretreatment, without subsequent compilation; -I specifies the header file directories specified here is our custom header file directories; -o specifies the output file name.
After much larger volume will be preprocessed code:
X-
name File
File size
number of lines of code
before pretreatment
test.c
146B
. 9
after pretreatment
test.i
17691B
857
programs or text after pretreatment, can be opened with a text editor.
2. Compile (Compilation)
compilation process herein does not mean all of the program from the source file to binary, but to undergo a process of converting into a specific pre-treatment after the assembly code (assembly code) process. Specify the following compilation:
GCC -S -I./inc test.c -o test.s
above command -S allow the compiler to compile after stopping, the subsequent process is not performed. After the compilation process is completed, it will generate assembly code test.s program, which is a text file, reads as follows:
The results test.s after // test.c compilation
.file "test.c"
.section .rodata
.LC0:
. String "% A = D, B = D%, D% = A + B \ n-"
.text
.globl main
.Type main, @function
main:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
andl $-16, %esp
subl $32, %esp
movl $2, 20(%esp)
movl $3, 24(%esp)
movl 24(%esp), %eax
movl %eax, 4(%esp)
movl 20(%esp), %eax
movl %eax, (%esp)
call add
movl %eax, 28(%esp)
movl 28(%esp), %eax
movl %eax, 12(%esp)
movl 24(%esp), %eax
movl %eax, 8(%esp)
movl 20(%esp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
RET
.cfi_endproc
.LFE0:
.size main, main-.
.ident "GCC: (Ubuntu 4.8.2-19ubuntu1) 4.8.2"
.section .note.GNU-Stack, "", @ PROGBITS
3. Assembler (Assemble)
the last step of the assembly process assembly code into machine code (machine code), this step produces a file called object files in binary format. gcc compilation process by as command completion:
as test.s -o test.o
equivalent to:
gcc -o -c test.s test.o
This step will produce an object file for each source file. Thus mymath.c also need to generate a file mymath.o
4. link (Linking)
linking a plurality of object files and processes required library (.so, etc.) into the final executable file links (executable file).
Command is as follows:
LD -o test.o inc is test.out / mymath.o ... ... Libraries
Reference: https: //www.cnblogs.com/CarpenterLee/p/5994681.html#top

Guess you like

Origin www.cnblogs.com/GuoHail/p/12233590.html
Recommended