The preprocessor is a program that runs before the compiler and changes the source text of our programs.

Preprocessor Directives

#include

  • #include 是一个编译预处理指令, 和宏一样, 在编译之前就处理了
  • 它把那个文件的全部文本内容原封不动地插入到它所在的地方
    • 所以也不是一定要在.c文件的最前面 #include

🔗Header

"" 还是 <>

  • "" 要求编译器首先在当前目录 (.c文件所在的目录) 寻找这个文件, 如果没有, 到编译器指定的目录去找
  • <> 让编译器只在指定的目录去找

include 的误区

  • #include 不是用来引入库的
  • stdio.h 里只有 printf 的原型, 其代码在另外的地方, 某个.lib或.a中
  • 现在的C语言编译器默认会引入所有的标准库
  • #include <stdio.h> 只是为了让编译器知道 printf 函数的原型, 保证调用时给的参数值是正确的类型

#define