LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: sybaselu

这几种函数有何区别?

[复制链接]
发表于 2004-8-3 09:56:23 | 显示全部楼层
需要节省空间的时候,往往会考虑不用系统的crt库里面默认的初始化代码。这个时候就可以自定义程序入口,VC里面,通常是用#pragma comment(linker, "/ENTRY:EntryPoint"),在EntryPoint这个函数里面可以自己做需要的初始化,或者直接去调用main之类。如果用gnu的toolchain的话,可以用ld -e entry
       -e entry
       --entry=entry
           Use entry as the explicit symbol for beginning  execu-
           tion  of  your  program, rather than the default entry
           point.  If there is no symbol named entry, the  linker
           will  try  to parse entry as a number, and use that as
           the entry address (the number will be  interpreted  in
           base  10;  you  may use a leading 0x for base 16, or a
           leading 0 for base 8).
发表于 2004-8-3 10:37:56 | 显示全部楼层
不错,多谢
发表于 2004-8-3 16:37:50 | 显示全部楼层
从isoc99的规范来看,只有int main(int argc,char *arg[])才符合规范。
其它的乱七八糟的东西就是gcc或者vc的扩展了。
发表于 2004-8-3 17:07:16 | 显示全部楼层
记忆中C99 不是这么说的吧。又查了一下:
[PHP]
5.1.2.2.1 Program startup
1 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;9) or in some other implementation-defined manner.
[/PHP]
只要返回int,名字是main就可以了。
btw,C99只是说了使用标准的CRT的时候,开始一定会调用main。使用自己的初始化代码,就跳过了标准CRT的初始化部分,自然不会有调用main,这个时候就需要自己做初始化,自然要告诉链接器从哪个函数开始。况且这个时候处理的是一堆.o的文件,基本上已经和语言无关了,完全可以自己用汇编做一下初始化,然后链接时候把这个模块指定为程序起始。
发表于 2004-8-5 20:44:54 | 显示全部楼层

int main(int, char**)应该是strict-prototype吧

此外还有
int main(int argc, char** argc, char** envp);
 楼主| 发表于 2004-8-6 08:59:44 | 显示全部楼层
int main(int argc, char* argv[])或int main(int argc, char** argv[])这两种标准吧!其他都是扯蛋!
发表于 2004-8-6 10:06:06 | 显示全部楼层
最初由 sybaselu 发表
int main(int argc, char* argv[])或int main(int argc, char** argv[])这两种标准吧!其他都是扯蛋!

int main(int argc, char** argv[])是标准吗?写错了吧。
发表于 2004-8-6 10:52:04 | 显示全部楼层
肯定不是,上面不是有C99的标准吗,写的很清楚
发表于 2004-8-6 10:59:21 | 显示全部楼层
最初由 lucifer 发表
肯定不是,上面不是有C99的标准吗,写的很清楚

在下支持lucifer兄。
发表于 2004-8-6 12:06:59 | 显示全部楼层
int main(int argc, char** argv[])
呵呵,肯定是写错了(:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表