有关main函数的前因后果
2007-07-14 10:48
176 查看
以下内容摘自原文:
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.
详细内容见:http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=11485&lngWId=3
下载:Download article
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.
详细内容见:http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=11485&lngWId=3
下载:Download article
相关文章推荐
- ucos在s3c2410上运行过程整体剖析-从main函数到UCOS初始化完毕 分类: μc /os ii 系统有关知识 2012-03-13 21:37 1740人阅读 评论(0) 收藏
- ucos在s3c2410上运行过程整体剖析-从加电到执行main函数 分类: μc /os ii 系统有关知识 2012-03-13 21:27 2409人阅读 评论(1) 收藏
- SDL闹腾(一):SDL有关main函数的问题(第一天开始瞎折腾……)
- 有关数据源的问题,搞掂你,shit!!!
- 牛人林达华推荐有关机器学习的数学书籍
- 产品设计体会(7024)有关交互设计,读过的6本书
- JBOSS7编码设置(解决中文乱码有关)
- 有关交互设计,读过的6本书
- 有关AVL平衡二叉树的旋转
- 软考中有关死锁的问题
- main函数的参数
- 有关AS3编程的一些总结
- 有关ie浏览器怪异模式(Quirks Mode)对 HTML 页面的影响的解决办法
- Solaris有关指令
- 有关类中initialization初始化的一些说明
- HTML 5删除开源视频编码Ogg 据称与苹果有关
- 有关td使用colspan属性后导致td不能充满整个tr的问题解决方法
- 有关SwfUpLoad的2038 错误
- 有关git
- 谈谈有关各数据库Blob、Clob类型字段的读取、保存更新