Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 MVisualC++ 2010,当我尝试取消定义“main”时,没有结果,控制台照常启动。我期待一些丢失的入口点错误或其他东西。这是为什么?
#undef main int main() { }
main 不是一#define开始的。你的#undef改变一点也没有。
#define
#undef
#define foo bar告诉预处理器“用 bar 替换所有出现的 foo”。 #undef foo告诉预处理器“foo 不再有特殊含义,保持原样”
#define foo bar
#undef foo
如果您想要链接器错误,请重命名main为 eg main2,或执行以下操作:
main
main2
void foo(); int main() { foo(); }
这告诉编译器一个foo函数存在(但不是它是什么)。main尝试使用它,因此链接器在找不到它时会出错。
foo