Program without main()

Please support our C++ advertiser: Intel Parallel Studio Home
Closed Thread

Join Date: Apr 2008
Posts: 3
Reputation: rukunaditya is an unknown quantity at this point 
Solved Threads: 0
rukunaditya rukunaditya is offline Offline
Newbie Poster

Program without main()

 
0
  #1
Apr 13th, 2008
Is it possible to print anything on screen in C or C++ without using main().If yes please explain how?
Quick reply to this message  
Join Date: Mar 2008
Posts: 1,443
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 118
Sponsor
William Hemsworth William Hemsworth is online now Online
Nearly a Posting Virtuoso

Re: Program without main()

 
0
  #2
Apr 13th, 2008
main() is the start of any C++ application, why do you need to do it without it ?
Quick reply to this message  
Join Date: Apr 2008
Posts: 3
Reputation: rukunaditya is an unknown quantity at this point 
Solved Threads: 0
rukunaditya rukunaditya is offline Offline
Newbie Poster

Re: Program without main()

 
0
  #3
Apr 13th, 2008
Originally Posted by williamhemswort View Post
main() is the start of any C++ application, why do you need to do it without it ?
In one of the programming competetions in my college we were asked to do this.
Although none was successful
Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Program without main()

 
0
  #4
Apr 13th, 2008
Because it's a frequent teaser question which some tutors think are useful in some way.
Like for example printing without using a ; or making the program print it's source code or some other dumb trick.
Quick reply to this message  
Join Date: Aug 2005
Posts: 15,462
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1476
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Program without main()

 
0
  #5
Apr 13th, 2008
>>Is it possible to print anything on screen in C or C++ without using main().

Yes -- write a MS-Windows win32 api program which uses WinMain() instead of main(). Or use VC++ 2008 and it will generate a console program that starts with _tmain().
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Quick reply to this message  
Join Date: Apr 2008
Posts: 3
Reputation: rukunaditya is an unknown quantity at this point 
Solved Threads: 0
rukunaditya rukunaditya is offline Offline
Newbie Poster

Re: Program without main()

 
0
  #6
Apr 14th, 2008
Thanks very much for your reply.But please I need some more help or atleast some hints as I dont know how to create a MS-Windows win32 api program which uses WinMain() instead of main(). I am new at programming . So please help
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,740
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 739
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Program without main()

 
1
  #7
Apr 14th, 2008
>So please help
Try searching for WinMain on www.google.com. Seriously, it's not that hard to do a little bit of research and come up with something. We tend not to take kindly to willfully clueless people.
I'm here to prove you wrong.
Quick reply to this message  
Join Date: Jan 2008
Posts: 7
Reputation: eager is an unknown quantity at this point 
Solved Threads: 2
eager eager is offline Offline
Newbie Poster

Re: Program without main()

 
0
  #8
Apr 14th, 2008
Every ISO standard C/C++ program must have a main(). Windows, other graphic environments, and many embedded systems have a non-standard environment and may not need a main().

So, the answer is: in ISO Standard C/C++, you cannot print anything without having a main() function. If you are talking about a non-standard environment, then the answer is it depends on the environment.
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,740
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 739
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Program without main()

 
1
  #9
Apr 14th, 2008
>So, the answer is: in ISO Standard C/C++, you cannot
>print anything without having a main() function.
Unless you're on a freestanding implementation.
I'm here to prove you wrong.
Quick reply to this message  
Join Date: May 2009
Posts: 3
Reputation: abhishekp has a little shameless behaviour in the past 
Solved Threads: 0
abhishekp abhishekp is offline Offline
Newbie Poster

Re: Program without main()

 
-3
  #10
May 26th, 2009
Ok the question asked is never print anything without main() function. The question asked is without anything in main function and it is possible(I know it because i myself have asked this question many times). You can do just about anything without anything inside main() function. The answer is C++ -> class -> global object. Try it and you'll see.
Last edited by abhishekp; May 26th, 2009 at 11:35 am.
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC