Saturday 6 August 2011

Writing a C program without a main()


We all are aware of what C programming language is. We often write huge programs which has numerous lines of code, but have you ever thought of writing a C program without a "main()" header??
You probably must be thinking this guy is nuts. But I haven't gone nuts yet studying my C & 
C++ books prescribed in my engineering college syllabus. And its possible to write a code in C programming language without using a main header.




 
let me show you how this can be done. 



#include<stdio.h>
#define decode(c,o,m,p,u,t,e,r)p##e##u##t
#define begin decode (t,e,r,m,i,n,a,l)
int begin()
{
printf("Demo of code without main");
}
 

Try running this program, and you will find it runs perfectly fine even without a main header.



Well now lemme tell you the truth, its not that I haven't used "main", its just that I have coded it in something else. A very small trick is involved here. Here the trick is done with the help of "#define" in the line 2 and 3.

In line 2:
#define decode(c,o,m,p,u,t,e,r)p##e##u##t


Here "##" operator is "Token merging operator" or pasting operator which merge two or more character together. Now in the line 2 (c,o,m,p,u,t,e,r) is expanded to “peut” as ## operator merges “p##e##u##t” to “peut”. The logic is when you pass (c,o,m,p,u,t,e,r) as argument it merges the 4th,7th,5th, and the 6th characters.


Now check the line 3:
#define begin decode(t,e,r,m,i,n,a,l)


Here again the preprocessor replaces the macro start with the expansion decode(t,e,r,m,i,n,a,l). As the macro definition in the line 2 the argument must be expanded so that the 4th,7th,5th, 6th characters must be merged. In the argument (t,e,r,m,i,n,a,l) 4,7,5, 6 nd characters are ‘m’,’a’,’i’, ‘n’.


So the fourth line “int begin” is replaced by “int main” by the preprocessor before the program is passed on for the compiler. Hence our program runs successfully.





This is a small trick which makes people believe that a program or piece of code can run without main.

Tuesday 3 May 2011

Udaan!






















Abhi to maa ki god se nikle hain,
zara utar ker khade to ho lein,
In nanhein kadmo per khud ko khada hone to do,
Gir ker khud ko samhalne to do,
sapno ko paane ka asankhya raste hain,

kuch ek rasto per safar kerne to do,
khusiyon ka jo ek gaon hai,
bahut durr,
Us gaon mai jaker zara busne to do...



Abhi to bahar nikelin hain andoo se,

Pankh chote hain abhi,
unko zara ugne to do,

bade hoker zara failne to do,
Ghosle se nikal ker zara asaman ki taakne to do,
Pehli udan mai zara gir ker fir udne to do,
Fir "Udaan" apni hai,
Lambi aur durr tak.....


Tumhari Wo Alsaayi Aakhein!!!

Tumhari wo alsaayi aakhein,
der raat tak jagi hui,
puri nind se, vanchit.

Subeh, khulne ko tyar nahi hoti.
 
Aakhon ki tarai mai kajal

tumhara, bikhra hua.
Aisa lagta hai jaise,
kale megho ke bich tapta suraj,
per thoda murjhaya hua.


Kitni masakkat se khulti hai

wo kajrari aakhein,
Sapno ki dibiya band ker ke,
apni khawabo ki hasin duniya
ko chod ker....


wo tumhari pyari alsaayi aakhein....









Maine samay ko badalte dekha hai!

Maine samay ko badalte dekha hai,

Pal bher mai jeevan ko guzarte dekha hai...

Maa ki god mai un bhishan shardiyo,
ko chu-mantar hote dekha hai.
Kabhi papa ke darr se, khud ko,
maa ke achal mai chupte dekha hai.
Bhai se hui un asankhya ladai ke baad,
ki chuppi ko dekha hai.
Befikri ki us mast maula jeevan ko, 
sapno mai khote dekha hai.
Bachpan ki shararato ko yaad kerke,
khud ko haste hue dekha hai.
Aur, apne pyare se bachpan ko,
khuli aakhon se ojhal hote dekha hai...


Shayad maine samay ko badalte dekha hai...
 
Dheere se chadte is kishora-awastha,
ke rang ko dekha hai.
Yaar dosto ke sang,
khud ko her galat kam kerte dekha hai.
Papa ke paise per,
khud ko hazaro ayiyashiyo mai doobe dekha hai.
Us pehle pyaar ke khone per,
khud ko akele sisakte dekha hai. 
Jeevan mai kuch banane ki chah ko,
hatash hoker chhutate dekha hai.
Rishto ki uchayiyo se,
khud ko girte dekha hai.
Faiz, Firaq, Bachchan, Dinker ke shabdo mai,
khud ko ramte dekha hai.
Jaisa hoon mai, khud ko,
waisa bante dekha hai...



Shayad, maine samay ko badalte dekha hai....