c program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sulekhasweety@gmail.com

    c program

    Hi,

    can any one give a brief outline of the different stages in the
    execution of a C program , in terms of compilation, pre-processing,
    linking etc
  • pete

    #2
    Re: c program

    sulekhasweety@g mail.com wrote:
    Hi,
    >
    can any one give a brief outline of the different stages in the
    execution of a C program , in terms of compilation, pre-processing,
    linking etc
    No.
    A C implementation can do two different things.
    It can translate a C program.
    It can execute a C program.

    Compilation, pre-processing, linking are related to translation.

    N869

    5.1.1.2 Translation phases

    [#1] The precedence among the syntax rules of translation is
    specified by the following phases.5)

    1. Physical source file multibyte characters are mapped
    to the source character set (introducing new-line
    characters for end-of-line indicators) if necessary.
    Trigraph sequences are replaced by corresponding
    single-character internal representations .

    2. Each instance of a backslash character (\) immediately
    followed by a new-line character is deleted, splicing
    physical source lines to form logical source lines.
    If, as a result, a character sequence that matches the
    syntax of a universal character name is produced, the
    behavior is undefined. Only the last backslash on any
    physical source line shall be eligible for being part
    of such a splice. A source file that is not empty
    shall end in a new-line character, which shall not be
    immediately preceded by a backslash character before
    any such splicing takes place.

    3. The source file is decomposed into preprocessing
    tokens6) and sequences of white-space characters
    (including comments). A source file shall not end in
    a partial preprocessing token or in a partial comment.
    Each comment is replaced by one space character. New-
    line characters are retained. Whether each nonempty
    sequence of white-space characters other than new-line
    is retained or replaced by one space character is
    implementation-defined.

    4. Preprocessing directives are executed, macro
    invocations are expanded, and _Pragma unary operator
    expressions are executed. If a character sequence
    that matches the syntax of a universal character name
    is produced by token concatenation (6.10.3.3), the
    behavior is undefined. A #include preprocessing
    directive causes the named header or source file to be
    processed from phase 1 through phase 4, recursively.
    All preprocessing directives are then deleted.

    5. Each source character set member and escape sequence |
    in character constants and string literals is
    converted to the corresponding member of the execution
    character set; if there is no corresponding member, it
    is converted to an implementation-defined member.

    6. Adjacent string literal tokens are concatenated.

    7. White-space characters separating tokens are no longer
    significant. Each preprocessing token is converted
    into a token. The resulting tokens are syntactically
    and semantically analyzed and translated as a
    translation unit.

    8. All external object and function references are
    resolved. Library components are linked to satisfy
    external references to functions and objects not
    defined in the current translation. All such
    translator output is collected into a program image
    which contains information needed for execution in its
    execution environment.


    --
    pete

    Comment

    • Richard Heathfield

      #3
      Re: c program

      sulekhasweety@g mail.com said:
      Hi,
      >
      can any one give a brief outline of the different stages in the
      execution of a C program , in terms of compilation, pre-processing,
      linking etc
      There are eight translation phases. They are documented in the C Standard.
      Briefly, they are:

      1) physical source file characters are mapped to the source character set,
      and trigraph replacements happen;
      2) line splicing happens;
      3) source file is decomposed into pp-tokens; comments are removed (replaced
      by one space character);
      4) preprocessing directives are executed and macro invocations are
      expanded;
      5) escape sequences are converted into characters;
      6) string literal concatenation occurs;
      7) pp-tokens are converted to tokens, and translation (compilation, if you
      like) occurs;
      8) linking.

      --
      Richard Heathfield <http://www.cpax.org.uk >
      Email: -http://www. +rjh@
      Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
      "Usenet is a strange place" - dmr 29 July 1999

      Comment

      • smarty

        #4
        Re: c program

        On May 10, 4:19 pm, sulekhaswe...@g mail.com wrote:
        Hi,
        >
        can any one give a brief outline of the different stages in the
        execution of a C program , in terms of compilation, pre-processing,
        linking etc
        1.the file u create in editor is saved as ".c" file
        2. this '.s' file is then PREPROCESSED for compilation .
        3. the preprocessed file undergoes compilation to generate a
        '.asm' (assembly file) or '.s' or '.src' file.
        4. this source file is assembled to generate a '.obj' file
        5. this .obj file is combined with other '.obj' or '.lib' files to
        generate an executable file.

        Comment

        • Chris H

          #5
          Re: c program

          In message
          <11fc6b6d-2276-45e0-9d53-bca2d0e04995@j3 3g2000pri.googl egroups.com>,
          smarty <csmgsarma@gmai l.comwrites
          >On May 10, 4:19 pm, sulekhaswe...@g mail.com wrote:
          >Hi,
          >>
          >can any one give a brief outline of the different stages in the
          >execution of a C program , in terms of compilation, pre-processing,
          >linking etc
          >
          >1.the file u create in editor is saved as ".c" file
          >2. this '.s' file is then PREPROCESSED for compilation .
          >3. the preprocessed file undergoes compilation to generate a
          >'.asm' (assembly file) or '.s' or '.src' file.
          >4. this source file is assembled to generate a '.obj' file
          >5. this .obj file is combined with other '.obj' or '.lib' files to
          >generate an executable file.
          1 You write text (C source) in to a TEXT editor. Often the editor in an
          IDE

          2 You "Compile" the source.
          These days this will give you an object file for linking.
          Under the hood there are several steps

          2.1 The pre-processor does a *textual* replacement of macros and
          defines. This is why it is often required that macros have ( ) around
          them when they are defined.

          2.2 the now expanded text file is compiled. At one time this could be
          up to THREE passes and the command "CC file.c" actually fed file.c to a
          batch file called cc that called the three parts of the compiler. This
          would turn our assembler code in a text file. You then needed to
          assemble the text file to object code.

          Modern compilers are "single pass" which means they hide all the
          messing about and go from the source code text to object files in "one
          pass" and do not generate assembler code. Thus a separate assembler is
          not needed. In reality there is usually a pre-proccessor phase and the
          compiler will generate intermediate files and tables.

          These days there is more memory. In the Good old Days you use to have to
          swap floppy disks for compile, assemble and link phases :-) (and 8inch
          floppies at that :-))))

          3 linking. This links the various program object files and the library
          files

          linking needs to sort out all the extern function and data calls between
          modules and the library. It knits the modules together in one object
          file

          In some cases years ago where there is only a single file and no calls
          to the library the object file from the assembler or compiler could run
          without linking.

          The out put from the linker can be further processed to give S-Rec,
          Intel Hex or other files for downloading to eprom/flash programmers.

          --
          \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
          \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
          \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



          Comment

          Working...