please help me..
Yes it is possible to write a program in c without using main.
Here is the code:[code=c]
/* prog_without_ma in.c */
_start()
{
_exit(my_main() );
}
int my_main(void)
{
printf(”Hello\n ”);
return 42;
}[/code]
And use this command (% is command prompt) to compile:
%gcc -O3 -nostartfiles prog_without_ma in.c
Try compiling this example:[code=c]
#include<stdio. h>
#define decode(s,t,u,m, p,e,d) m##s##u##t
#define begin decode(a,n,i,m, a,t,e)
void begin()
{
printf(”hello”) ;
}[/code]
here is how it works once we say define we need to understand that
#define x y
then ‘x’ ix replaced by ‘y’
similarly in this case
#define begin decode(a,n,i,m, a,t,e)
decode(a,n,i,m, a,t,e) is replaced by m##a##i##n
bcoz s is replaced by a,t by n,u by i and so on
s->a
t->n
u->i
m->m
p->a
e->t
d->e
now the statement becomes
void m##a##i##n
And u must be knowing that ## is used for string concatenation so it becomes
“main”
finally the code crops down to[code=c]
void main()
{
printf(”hello”) ;
}[/code]
Yes it is possible to write a program in c without using main.
Here is the code:[code=c]
/* prog_without_ma in.c */
_start()
{
_exit(my_main() );
}
int my_main(void)
{
printf(”Hello\n ”);
return 42;
}[/code]
And use this command (% is command prompt) to compile:
%gcc -O3 -nostartfiles prog_without_ma in.c
Try compiling this example:[code=c]
#include<stdio. h>
#define decode(s,t,u,m, p,e,d) m##s##u##t
#define begin decode(a,n,i,m, a,t,e)
void begin()
{
printf(”hello”) ;
}[/code]
here is how it works once we say define we need to understand that
#define x y
then ‘x’ ix replaced by ‘y’
similarly in this case
#define begin decode(a,n,i,m, a,t,e)
decode(a,n,i,m, a,t,e) is replaced by m##a##i##n
bcoz s is replaced by a,t by n,u by i and so on
s->a
t->n
u->i
m->m
p->a
e->t
d->e
now the statement becomes
void m##a##i##n
And u must be knowing that ## is used for string concatenation so it becomes
“main”
finally the code crops down to[code=c]
void main()
{
printf(”hello”) ;
}[/code]
Comment