|
Probably not:
a callback, also known as a "call-after"[1] function, is any executable code that is passed as an argument to other code that is expected to call back (execute) the argument at a given time.
So to be a callback function it would need to be passed as an argument to some other function, and I can't see any good reason to do that when you can call it directly or via a function pointer / function table that is set by the compiler / linker.
That you can't call main at all except from a single point in your app kinda backs that up as well!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Yes, but I kind of expect the OS to call my method at the given time of the process starting up...? And the address is passed to the OS to be called back on, just through an extra layer of module EXPORTS etc.
It's a pedant's dream this. I should move on.
Regards,
Rob Philpott.
|
|
|
|
|
The OS doesn't call your main method at all - there are three places it can start: the MZ Stub (which for Windows apps will just print "this program cannot be run in MSDOS mode" and quit the app), the NE or (for more modern apps) the PE: Portable Executable - Wikipedia[^].
And EXE files (even old MSDOS 16 bit apps) don't call main immediately anyway, they do allocation and static initialisation before they are ready to start running the code you wrote!
"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?"
|
|
|
|
|
|
It called me back once, but it was drunk at the time.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Did it say - "I want to C you again!" ?
And did you reply #ly that you had moved on?
I, for one, like Roman Numerals.
|
|
|
|
|
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!
|
|
|
|
|
So it was yaccing with a lisp?
I, for one, like Roman Numerals.
|
|
|
|
|
Did you give it your number, baby?
#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
|
|
|
|
|
It probably depends on the language, compiler, system, etc.
As far as I know, in the languages I use, there nothing special about call-back functions, it's only about how an ordinary function is used.
There's no reason to declare that no language will ever allow it.
I seem to recall having a desire for a recursive main. : ) Just because.
modified 22-Jan-20 11:51am.
|
|
|
|
|
How dare you ask programming questions in the lounge?!! I'm outraged.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Yeah, it's good to be reckless sometimes. Send me the codez and I'll go away.
Regards,
Rob Philpott.
|
|
|
|
|
I figure every function is a callback function - it's just a matter of perspective.
Real programmers use butterflies
|
|
|
|
|
It's an "entry point"; "Main" wasn't something that was part of a "response", other than "call static Main in class x".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
If you take the view that your application is an interruption to a busy operating system's schedule, but it figures it should let you do your thing before you whine and get all bitchy about it, then yes, it is a callback function.
Software Zen: delete this;
|
|
|
|
|
Are you asking if it's masculine or feminine?
I've no idea, and I don't want to look, just in case.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Only if used as such, e. g. in this code:
#include <iostream>
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]: 3
The 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)
|
|
|
|
|
No. It's a state in the Northeast.
Oh Well.....
|
|
|
|
|
Ever seen an Antelope? It's incredible how they get that little ladder up to the nest window.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Then they flea to the circus.
It's been 6 months since I joined the gym and there's been no progress. I'm going there tomorrow in person to find out what's really going on!
JaxCoder.com
|
|
|
|
|
... or just roll along with the dung beetles
after many otherwise intelligent sounding suggestions that achieved nothing the nice folks at Technet said the only solution was to low level format my hard disk then reinstall my signature. Sadly, this still didn't fix the issue!
|
|
|
|
|
I gnu[^] you'd turn that into a pun!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
They do not have opposable thumbs so they could never use a ladder.
Therefore they canteloupe you melon head!
I, for one, like Roman Numerals.
|
|
|
|