- 论坛徽章:
- 0
|
本帖最后由 timothyqiu 于 2013-01-13 19:18 编辑
比如 C99 标准:
The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent; or in some other implementation-defined manner.
也就是说,整个程序就是通过从外部调用本程序的一个叫 main 的函数开始的。
- int main(void)
- int main(int argc, char *argv[])
- 其它由具体实现定义的形式(比如有的实现还定义了 int main(int argc, char *argv[], char *env[]) 的形式)
所以 main 和其它函数没什么大区别,只不过要求你写成某种形式。
至于省略写 int main(void),多是用不到 argc argv 什么的话这么写省字数(也省键盘……不然真成 keyboard killer 了……)
(至于为什么可以允许这么多种形式存在,多是因为 cdecl 是调用者清栈的。当然不一定都是这样。)
至于「多级指针」,就是一种指针,这种指针指向另一个指针(如此往复)……
为什么把 argv 称作「多级指针」呢?因为参数中的 char *argv[] 可以写成 char **argv (参考 @Ager 大神之前的帖子 http://bbs.chinaunix.net/thread-4060180-1-1.html)…… |
|