c语言gcc编译*.i文件#3""2这是什么?

c language gcc compiler *.i file #3 "" 2 what is this?

//main.c
#include <stdio.h>
#include "swap.h"

int main(void){
    return 0;
}

.

//swap.h
void swap(int* a, int* b){
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

我想知道预处理器在编译器中是如何工作的。

所以我开始从预处理器分析。

我尝试在终端中进行预处理。

gcc -E  c.c -o c.i

在此代码中。

我有一个问题。

# 2 "c.c" 2
# 1 "swap.h" 1

# 1 "swap.h"
void swap(int* a, int* b){
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}
# 3 "c.c" 2

extern void hello(void);

int main(void){
    return 0;
}

在此代码中。

# 2 "c.c" 2
# 1 "swap.h" 1
# 3 "c.c" 2

这个代码是什么意思?

换句话说,#和数字是什么意思?

.c”和“.h”是什么意思?

这些指令指示输出中特定代码行的来源。

前两个字段是从该点开始的原始文件的行号和源文件名。之后的任何数字都是标志

来自 GCC documentation 预处理器输出:

Source file name and line number information is conveyed by lines of the form

# linenum filename flags

These are called linemarkers. They are inserted as needed into the output (but never within a string or character constant). They mean that the following line originated in file filename at line linenum. filename will never contain any non-printing characters; they are replaced with octal escape sequences.

After the file name comes zero or more flags, which are ‘1’, ‘2’, ‘3’, or ‘4’. If there are multiple flags, spaces separate them. Here is what the flags mean:

‘1’ This indicates the start of a new file.

‘2’ This indicates returning to a file (after having included another file).

‘3’ This indicates that the following text comes from a system header file, so certain warnings should be suppressed.

‘4’ This indicates that the following text should be treated as being wrapped in an implicit extern "C" block.