le****@gmail.co m wrote on 15/07/05 :
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?
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++