C99 - 5. Environment

5.1.1.1 Program structure

前置處理器

  • Definition

    • in C99,
      • 5.1.1.1 Program structure p1:
        A C program need not all be translated at the same time.
        The text of the program is kept in units called source files, (or preprocessing files) in this International Standard.

        在ISO, 程式的文本是由source file (or preprocessing file)為單位所組成。

        A source file together with all the headers and source files included via the preprocessing directive #include is known as a preprocessing translation unit. After preprocessing, a preprocessing translation unit is called a translation unit.

        一個source file是透過preprocessing directive # 將其從preprocessing translation unit 轉譯成 translation unit

        Image Not Showing Possible Reasons
        • The image file may be corrupted
        • The server hosting the image is unavailable
        • The image path is incorrect
        • The image format is not supported
        Learn More →
        綜合上述兩個註解;translation unit為一個source file, 且包含透過前置處理導引;前置處理器指示將外在宣告(External Declaration),headers和source files包含進來。包含進來的方式有:

        • 動態連結:在程式執行時,到對應的記憶體位置找對應的指令(利用symbol table)。
        • 靜態連結:做preprocessing時,透過#include directive將header的內容貼到translation unit中。
  • History
    在ISO C之前早期的C 語言編譯器, 發展於1972-1973 年間,被稱為 “Very early C compilers” 的實作中,不存在 C preprocessor (!)

    摘錄自:你所不知道的 C 語言:前置處理器應用篇 - 前置處理器是後來才納入 C 語言的特徵