Step C language compiler gcc

A pretreatment

  -E gcc   xx.c ------> generate  .i   file

  Preprocessing work does not automatically generate the file

  Work:

     ① macro Alternatively , the first import file , conditional compilation , etc.

     ② remove the comment content  

Second, the compiler

  -S xx.i gcc -------> generated assembler .s

  Check grammar errors generated assembler

  Work:

    Check after pretreatment source code or error code syntax

Third, compilation

  -c xx.s gcc  -------> generate object files .o

  Work:

    The compiled assembly code into object files (binary)    is actually used as command

Fourth, the link

  xx.o GCC  ------> generate executable a.out

  Link one or more target files to generate an executable program a.out default is actually using the command ld

  Work: Link function call

  gcc * .o     link all object files to generate an executable program

  -o   can specify the destination file name

note:

Syntax error checking: at compile
the function call to check: the link stage

 

Preprocessing command
  instruction will be processed in the preprocessing stage
  at the beginning of instruction #

  A, # include the header file that contains    

    Import header file code
      need to import the file header of the standard library function calls
    #include <> and #include "" differentiated
      <> system from the specified path (configurable) contains the file search
      "" Search from the current directory header files included,
      if not found in the current directory, the directory specified by the system to search for the next
      use if containing write your own header file "," contains the standard library for general use <>

  二、#define

    Macro General uppercase
    1. macros are defined in the pretreatment stage a simple macro replacement
      #define the PI 3.14
    2. macro function
      #define POW (x) ((x ) * (x))
    pre-processing stage does not perform operation only replace

    Note: Do not define followed by the macro;
       the macro function need to give each parameter are put parentheses , and finally add a whole parentheses to avoid ambiguity
       between the macro function and parameter list can not have extra space

    3. \ Macros can be connected defined
      generally works only on a single line, but may be connected by \ multiple lines as a single macro definition
    4. # can be a string literal identifier into a
      #define tostr (X) #x is
      #define Print ( X) the printf (#x is "D =% \ n-", X)
    5. the identifier ## may generate a new
    role 6. macros:
      ① easy to modify
      ② simplify programming
      ③ parameter type no limitation flexible

    7. #define macro can be defined by the code can also be used to define the macro -D macro name at compile time

  Third, conditional compilation 

    Branch selection statement only if executed to determine which branch will execute two branches statements are compiled into the code to

    The option to compile code compile time  

      #if based on the value of the macro to perform conditional compilation
      #elif
      #else # or
      #endif # conditional compilation end of
      #ifdef #if defined if you define a macro using macro definitions to whether conditional compilation
      #ifndef If you do not define a macro
      # undef delete a macro to cancel the macro definition

 

      # ifdef / # ifndef / # if defined #endif // macro definitions to whether conditional compilation
      #if / # value elif #endif // macro to perform conditional compilation

    Header file guards:    

    It used to prevent multiple references to the header file
    if not a little more complex procedures may lead to repeated errors defined
      #ifndef XXX_H__
      #define XXX_H__

      
      #endif //XXX_H__

 

Guess you like

Origin www.cnblogs.com/jiangyu0331/p/11670974.html