One 、C Language program running process
- Choose a suitable program editing software , such as Notepad++, perhaps sublime Edit software , The more advanced ones are VSCode.
- Preprocessing ： The process is to copy the specific content of the header file from the specified path to the current program , If there are macro definitions in the program , Expand the macro definition , Delete all comments in the program at the same time . Generate a suffix of .i The file of .
The order is gcc hello.c -E -o hello.i
- compile ： The process is to check whether there are syntax errors in the source program , If it passes the test , Will .i Translation of files into assembly files . Generate a suffix of .s The file of .
The order is gcc -S hello.i -o hello.s
- assembly ： The process is to .s The file is translated into a binary object file that the machine can recognize . Generate a suffix of .o The file of .
The order is gcc -c hello.s -o hello.o
- link ： The process is to involve this program to all the target files, that is .o file 、 library “ Adhesion ” together , Get the final executable .
example ： If the program is designed to printf function , Then the corresponding printf.o file , The linking process is to involve these .o The files are all linked together .
The order is gcc hello.o -o hello
- About main The parameters of the function main(int argc , char * argv )
- argc The original meaning is argument count Translated into The amount of content . The concrete meaning means Pass to main The number of arguments to the function （ A few strings of characters ）.
- argv The original meaning is argument value Translated into The exact meaning of the content . The specific storage is passed to main The address of the string of the function .
argv There's the second one 0 The first address of a string
argv Holds the first address of the first string . … By analogy .
- About main The return value of the function
- return 0 Indicates that the program is executed correctly and exits normally
- return -1 Indicates that the program being executed has insufficient permissions
- return -2 The executed file does not exist
- return -3 Error executing code
- About the definition of header file
- #include “stdio.h” The header file defined by double quotation marks indicates that the header file is retrieved from the current path first , If you can't find , Then enter the standard C Search in database
- #include <stdio.h> Two angle brackets define the header file representation directly from the standard C Search the header file information in the database
- Generally speaking , Self defined header files use double quotes , Use angle brackets to call functions already written by the system . Such as ：stdio.h string.h etc. .
- About C The specific operation process of the program , It will be given in later chapters
All of the above are personal opinions , If there is a mistake , Welcome to correct .