main() is the start of any C++ application, why do you need to do it without it ?
William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
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.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
>>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().
Ancient Dragon
Retired & Loving It
30,042 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
>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.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>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.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
abhishekp is right, but not class only and not global only:
int main() {} // do nothing!!!
static struct __
{
__() { cout << "Hello..."; }
~__() { cout << "Bye!\n"; }
}
_;
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
You could hard code int main(){} as char main[] { /*opcodes*/ } (with extern "C" in VC++).
So technically it would then be main[] not main() anymore.
MosaicFuneral
Posting Virtuoso
1,691 posts since Nov 2008
Reputation Points: 888
Solved Threads: 116
I think it's impossible to solve undefined problem...
hosted or freestanding implementation... without main - with WinMain - with exotic compilers...
Nonsense ;)
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
>...and it is possible.
Now compare two problem definitions:
OP: >Is it possible to print anything on screen in C or C++ without using main().
#2: >Write a program in c or c++ to print "hello" without any statements in main() function.
Feel the difference.
;)
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
>Great Help!!!... sike, be a little more of a bitch next time
You're not looking any better, smart-ass. I love how those most vocal about me not being nice are so hypocritical. :)
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401