main() 是 C 中的预定义函数吗? [复制]

2024-04-04

可能的重复:
C、C++、Java、C# 中的 main() https://stackoverflow.com/questions/1539385/main-in-c-c-java-c

总的来说,我对编程很陌生,尤其是 C。我看过的每个示例都有一个“main”函数 - 这是以某种方式预定义的,这样该名称对编译器或运行时具有特殊含义......或者它仅仅是 C 程序员中的常见习惯用法(就像使用“foo”和“bar”作为任意变量名称)。


No, you need to define main in your program. Since it's called from the run-time, however, the interface your main must provide is pre-defined (must return an int, must take either zero arguments or two, the first an int, and the second a char ** or, equivalently, char *[]). The C and C++ standards do specify that a function with external linkage named main acts as the entry point for a program1.

至少正如该术语通常使用的那样,预定义函数将是诸如sin or printf它位于标准库中,因此您可以使用它而无需自己编写。

1If you want to get technical, that's only true for a "hosted" implementation -- i.e., the kind most of us use most of the time that produces programs that run on an operating system. A "free-standing" implementation (one produces program that run directly on the "bare metal" with no operating system under it) is free to define the entry point(s) as it sees fit. A free-standing implementation can also leave out most of the normal run-time library, providing only a handful of headers (e.g., <stddef.h>) and virtually no standard library functions.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

main() 是 C 中的预定义函数吗? [复制] 的相关文章

随机推荐