Is main() a callback function?
-
Well it never called me back - and I thought we had such a connection... :(( :(( :mad: :(( :((
I, for one, like Roman Numerals.
Did you give it your number, baby? ;P
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
-
Focused using butterflies
Real programmers use butterflies
honey the codewitch wrote:
Focused using butterflies
that are manipulated using gravitic lenses
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
-
honey the codewitch wrote:
Focused using butterflies
that are manipulated using gravitic lenses
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
created from the silk of butterfly cocoons :-D
Real programmers use butterflies
-
Difficult to tell, it was yelling a lot and slurring it's words.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
That reminds me of a thing I read some time back, titled something along the lines of 'the 50 things Windows does before hitting main()'. Can't find it but it's out there somewhere, by one of the SysInternals lot I think. It was both interesting and really boring at the same time.
Regards, Rob Philpott.
If you have Visual Studio you can see what the C run-time library does by looking at its source. I was checking that out just today.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
-
Actually things are a little different. In the Visual Studio source, VC/Tools/MSVC/**version**/crt/src/vcruntime/vcstartup_internal.h has the prototypes and the calls are in exe_common.inl. WinMain and main are two different calls along with their wide character versions.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
-
I can't make up my mind.
Regards, Rob Philpott.
Only if used as such, e. g. in this code:
#include
using namespace std;
static int call_countdown = 3;
typedef int (*MyCallbackFun)();
int foo(MyCallbackFun cb, int count)
{
static int foo_counter = 0;
++foo_counter;
cout << "enter foo[" << foo_counter <<"]: " << count << endl;
int result = cb();
cout << "exit foo[" << foo_counter << "]: " << result << endl;
return result;
}
int bar()
{
static int bar_counter = 0;
++bar_counter;
cout << "bar[" << bar_counter << "]" << endl;
return -1;
}
int main()
{
static int call_counter = 0;
++call_counter;
cout << "enter main[" << call_counter << "]" << endl;int result = 0; if (call\_counter < 5) { result = (call\_counter>2) ? foo(bar, call\_counter) : foo(main, call\_counter); } cout << "exit main\[" << call\_counter << "\]: " << result << endl; return call\_counter;
}
You can test it here: https://www.onlinegdb.com/online_c++_compiler[^] or trust me that the output is:
enter main[1]
enter foo[1]: 1
enter main[2]
enter foo[2]: 2
enter main[3]
enter foo[3]: 3
bar[1]
exit foo[3]: -1
exit main[3]: -1
exit foo[3]: 3
exit main[3]: 3
exit foo[3]: 3
exit main[3]: 3The tricky bit about this is that by using main() as a callback function, you're also using it recursively, which complicates matters considerably: it's easy to mess up the code and get an endless recursion. (that's why I added counters and output in every function) It's doable, but definitiely not a good idea.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
-
created from the silk of butterfly cocoons :-D
Real programmers use butterflies
lol, you got me there.
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
-
I suspected this might be the case, but I have not had access to the source for a number of years.
-
I can't make up my mind.
Regards, Rob Philpott.
No. It's a state in the Northeast. :laugh:
Oh Well.....