#ifdef #else #endif宏问题

ant*_*009 2 c code-formatting

我是C的新手,我正在维护代码.我在头文件中遇到过这个问题.我可以理解,如果源代码是在windows上编译的,它将进入if语句,如果代码在linux上编译,它将进入else语句.如果我错了,请纠正我.

但是,问题是为什么#(hash)在所有include头之前使用?

非常感谢任何建议,

#ifdef WIN32
#   include <conio.h>
#   include <process.h>
#   include <stdlib.h>
#   include <string.h>
#else
#   include <unistd.h>
#   include <termio.h>
#   include <sys/types.h>
#   include <sys/stat.h>
#   include <fcntl.h>
#endif
Run Code Online (Sandbox Code Playgroud)

Tom*_*ing 8

散列(#)表示预处理器指令.预编译器在编译之前运行代码,并根据以"#"开头的所有行执行操作."#include filename.h"指令基本上复制了filename.h的所有内容,并将其粘贴到"#include filename.h"行所在的位置.


abe*_*nky 7

#include是你在C中包含文件的方式.

您可能会对#和include之间的空格感到困惑.

但他们并不重要.这些行仍然是#include.