Pages - Menu

Saturday, 19 July 2014

Program without main in C.

Here is a simple C PROGRAM without using a main() function.



#include<stdio.h>
#define Compose(f,a,b,c,d,e) c##d##a##b
#define start Compose(f,i,n,m,a,f)
int start()
{
    printf("Hello.");
    return 1;
}

Concept:


## Concatenates two characters when we define start as decode(f,i,n,m,a,f) then it is decoded as main.
So there is a hidden main here.

Another program is





#include<stdio.h>
_start() { _exit(function_name()) } void funtion_name() { printf("Without main"); }

Compile it from command prompt as

$cc -nostartfile source_file.c

Third program is



#include<stdio.h>
#define start main
#define program ()
#define now {
#define end }
start program now
printf("Running fine");
end

No comments:

Post a Comment