以下内容摘自原文:
You would have been taught how main() is main in C? But, believe me, main() is nothing more than a word. i.e. It can be anything like Start(), Begin(), EntryPoint() etc. Before we directly go for main's hack, we must learn its basics. Here we go -
What main() is generally known for?
Ø
It's entry point of a C program.
Ø
Program without main() isn't possible.
Ø
main() executes first.
Ø
It has two parameters. i.e. argc, argv
Are these points right? See these possibilities...
Ø
A C program which doesn't have main().
Ø
A program which contains main() but is never called.
Ø
main() has three parameters i.e. argc, argv and environ or envp.
Every program contains an entry point which is the place from where the program starts its execution. Whenever we execute a program, it gets loaded into the memory (RAM). But, instead of starting the execution from main() OS passes the control to startup() function located in crt0.c OR in wincmdln.c (if console application). This function initializes the global and environment variables (OR Environment table) for the program. i.e. argc, argv, _osver, _winmajor, _winminor, _winver, environ. Startup routine passes the values of argc, argv and environ to main() and finally calls main().
/*
Author: Bindesh Kumar Singh
Date: March, 2007
*/
#include <windows.h>
#pragma comment(linker,"/ENTRY:EntryPoint") /* Entry point set to EntryPoint() */
void main() /* Never executes */
{
MessageBox(0,"inside main()","information",0);
}
void EntryPoint() /* Entry point */
{
MessageBox(0,"inside EntryPoint()","information",0);
}
main can be bypassed by using #pragma comments. Here EntryPoint() is set to be the entry point of program.
本文深入探讨了C程序的入口点main()函数,并解释了如何通过编译器指令指定不同的入口函数,如EntryPoint()。文章还介绍了程序加载到内存中后的执行流程,包括启动例程如何初始化全局变量并传递参数。
2570

被折叠的 条评论
为什么被折叠?



