没有main()的c程序? [英] c program without main( ) ?
问题描述
我将非常感谢您的帮助。
我们可以编写不包含main的交流码()
我听说这是可能的。真的有可能吗?
感谢你提前的帮助
lee
Hi, I will appreciate your assistance.
Can we write a c code which do not contain main()
I have heard that this is possible. Is it really possible?
Thanks for your help in advance
lee
推荐答案
le****@gmail.com 写道:
le****@gmail.com wrote:
我将非常感谢您的帮助。
我们可以编写不包含main的代码()
我听说这是可能的。真的可能吗?
Hi, I will appreciate your assistance.
Can we write a c code which do not contain main()
I have heard that this is possible. Is it really possible?
当然可以。 Win32程序员一直都这么做。
指定除main之外的入口点的C实现通常是名为freestanding的
。实现,以及对它们的要求远远不如托管实现那么严重,这个松散的名字比
的入口点是较低要求的一个例子。 />
(在Win32程序中,入口点通常称为WinMain。)
我们在没有main()的情况下编写C代码的更常见的情况是什么时候我们正在编写代码库,而不是实际的程序。该库是
单独构建,没有main(),然后链接到任何程序
希望使用它。
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
邮件:rjh在上面的域名
Yes, of course. Win32 programmers do it all the time.
C implementations which specify an entry point other than main are generally
called "freestanding" implementations, and requirements on them are far
less severe than on hosted implementations, this laxity over the name of
the entry point being one example of the lower requirements.
(In Win32 programs, the entry point is typically called WinMain.)
A more common situation in which we write C code without main() is when
we''re writing a code library, rather than an actual program. The library is
built separately, without main(), and then linked to whichever programs
wish to use it.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain
le **** @ gmail.com 于15/07/05写道:
le****@gmail.com wrote on 15/07/05 :
您好,我将非常感谢您的协助。
我们可以写ac吗代码不包含main()
我听说这是可能的。它真的可能吗?
Hi, I will appreciate your assistance.
Can we write a c code which do not contain main()
I have heard that this is possible. Is it really possible?
如果没有main(),就不可能编写符合要求的C程序。但是
main()函数可以嵌入到某些''框架库'中(比如
a GUI Windows应用程序)。
当我为dev-C ++编写代码时,我这样做:
我有一个包含main()函数的'framework.c'':
( http://mapage.noos .fr / emdel / clib.htm )
#include" ed / inc / sysalloc.h"
#include< string .h>
int main_(int argc,char * argv []);
static int is_opt(char const * const sopt,int const argc, char * const
* const argv)
{
int ok = 0;
int i;
= i; i< argc; i ++)
{
if(strcmp(sopt,argv [i]) )== 0)
{
ok = 1;
休息;
}
}
返回确定;
}
静态无效onexit(无效)
{
sys_mem_trace();
system(" pause");
}
int main(int argc,char * argv [])
{
static char Trace [1<< 11];
int trace = TRACE_OFF;
atexit(onexit);
if(argc> 1)
{
if(is_opt(" / t",argc,argv))
{
trace = TRACE_ON;
}
}
sys_mem_init(Trace,sizeof Trace,trace,NULL);
main_(argc,argv);
返回0;
}
和in我的''main.c'',我有:
#define main main_
#if 0
#include" ; ed / inc / sysalloc.h"
#include" ed / inc / sys.h"
#undef assert
#define断言(e)ASSERT(e)
#else
#include< assert.h>
#endif
/ *
-------------------------------------- --------------------------------
* /
int main()
{
/ *被测设备* /
返回0 ;
}
BTW,你为什么这么问?你的目标究竟是什么?
-
Emmanuel
C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
C库: http:// www.dinkumware.com/refxc.html
显然您的代码不符合原始规格。
"你用湿面条判处30睫毛。
- Jerry Coffin in alcc ++
It''s not possible to write a conforming C program without a main(). But
the main() function could be embedded in some ''framework library'' (Like
a GUI Windows application for example).
I do that when I write code for dev-C++ :
I have a ''framework.c'' containing the main() function :
(missing code at http://mapage.noos.fr/emdel/clib.htm)
#include "ed/inc/sysalloc.h"
#include <string.h>
int main_ (int argc, char *argv[]);
static int is_opt (char const *const sopt, int const argc, char *const
*const argv)
{
int ok = 0;
int i;
for (i = 1; i < argc; i++)
{
if (strcmp (sopt, argv[i]) == 0)
{
ok = 1;
break;
}
}
return ok;
}
static void onexit (void)
{
sys_mem_trace ();
system ("pause");
}
int main (int argc, char *argv[])
{
static char Trace[1 << 11];
int trace = TRACE_OFF;
atexit (onexit);
if (argc > 1)
{
if (is_opt ("/t", argc, argv))
{
trace = TRACE_ON;
}
}
sys_mem_init (Trace, sizeof Trace, trace, NULL);
main_ (argc, argv);
return 0;
}
and in my ''main.c'', I have :
#define main main_
#if 0
#include "ed/inc/sysalloc.h"
#include "ed/inc/sys.h"
#undef assert
#define assert(e) ASSERT (e)
#else
#include <assert.h>
#endif
/*
----------------------------------------------------------------------
*/
int main ()
{
/* device under test */
return 0;
}
BTW, why do you ask ? What exactly is your goal ?
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html
"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++
2005-07 -15 13:15:15 -0500, le****@gmail.com 说:
On 2005-07-15 13:15:15 -0500, le****@gmail.com said:
我将非常感谢您的帮助。
我们可以编写不包含main的代码吗()
我听说这是可能的。真的可能吗?
Hi, I will appreciate your assistance.
Can we write a c code which do not contain main()
I have heard that this is possible. Is it really possible?
是的,图书馆会这样做。
-
Sensei< se******@tin.it>
cd / pub
更多啤酒
Yes, a library would do that.
--
Sensei <se******@tin.it>
cd /pub
more beer
这篇关于没有main()的c程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!