我们以 hello.c 程序为例:

#include <stdio.h>

#define HELLOWORLD ("hello world\n")

int main(void)
{
    printf(HELLOWORLD); 
    return 0;
}

使用gcc -E hello.c -o hello.i命令,将 hello.c 文件预处理并且生成 hello.i 目标文件。

之前说道,预处理会将头文件包含进来并且会将宏定义进行替换,因此替换后的 hello.i 文件如下:

# 1 "hello.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "hello.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 27 "/usr/include/stdio.h" 3 4
.........

.........
typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;

typedef signed char __int8_t;
typedef unsigned char __uint8_t;
.........

.........
extern struct _IO_FILE *stdin;
extern struct _IO_FILE *stdout;
extern struct _IO_FILE *stderr;
extern FILE *fopen (const char *__restrict __filename,
      const char *__restrict __modes) ;
.........

.........

int main(void)
{
    printf(("hello world\n"));
    return 0;
}

可以看到将 stdio.h 文件包含进来,并且原封不动的将 HELLOWORLD 宏进行了替换。