使用 include<con> “杀死“ 编译器

一次尝试

  读者可以尝试如下代码,其中包含 #include <con>,不出意外的话你就"杀死"了你的编译器。

#include <con>
#include <stdio.h>
int main() {
	printf("Hello World!!!\n");
	return 0;
} 

原理

  运行了上面的代码,读者就会发现编译器没有反应了,编译器其实并不是真正意义上的"死掉"了,它只是在读取键盘。因为 con 是 Windows 保留文件名,表示标准输入输出,所以预处理器运行到这一行,就在等待你的键盘输入。类似的 Linux 下的 #include </dev/console> 有同样的效果。

posted @ 2021-11-30 19:18  Acx7  阅读(354)  评论(0编辑  收藏  举报