|
C is for wimps
Real programmers use butterflies
Real programmers use butterflies
|
|
|
|
|
Real programmers use galaxy-sized 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
|
|
|
|
|
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
|
|
|
|
|
created from the silk of butterfly cocoons
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 was just reading this yesterday[^]
Quote: All C++ programs must have a main function. If you try to compile a C++ .exe project without a main function, the compiler will raise an error. (Dynamic-link libraries and static libraries don't have a main function.) The main function is where your source code begins execution, but before a program enters the main function, all static class members without explicit initializers are set to zero. In Microsoft C++, global static objects are also initialized before entry to main. Several restrictions apply to the main function that do not apply to any other C++ functions. The main function:
* Cannot be overloaded (see Function Overloading).
* Cannot be declared as inline.
* Cannot be declared as static.
* Cannot have its address taken.
* Cannot be called.
But, maybe you are thinking it is a callback from the OS?
Or maybe you're just asking a rhetorical question?
|
|
|
|
|
Just pondering it really. Yes, I meant in effect it was called from the OS. Must admit I didn't know you couldn't call main() yourself - obviously never tried. Or quite possibly forgotten.
Then I started wondering what a callback function actually is (despite using them for years and years and years). It's just a function, and it's the way it's called that makes it a callback in a sense. And that made me think of indirect addressing rather than direct addressing at the low level. But then, are virtual functions callbacks? Not really but they are called indirectly...
I think it's time to go home.
Regards,
Rob Philpott.
|
|
|
|
|
raddevus wrote: * Cannot have its address taken.
* Cannot be called.
Lies. You can call main, and you can take its address. This compiles and runs in VS2019:
#include <iostream>
int main(int argc, char **argv)
{
if(argc <= 1) {
auto main_ptr{main};
std::cout << "pointer to main = " << main_ptr << std::endl;
std::cout << "exiting ..." << std::endl;
return 0;
}
std::cout << "argc = " << argc << std::endl;
main(--argc, argv);
}
Interestingly, in linux you auto main_ptr{main} is 1, but for windows it looks like an address: 0008151E
Update: I should also point out that the instances where you might need to call main from within you program are vanishingly small. In general, if you think you need to, you're almost certainly wrong.
|
|
|
|
|
That has always been my thought.
"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?"
|
|
|
|
|
|
No, it is just a function that gets called by the run-time library, framework etc. I have a feeling (vague memory) that you can tell the linker to use some other function as the starting point, but don't know why you would want to.
|
|
|
|
|
Richard MacCutchan wrote: don't know why you would want to
To annoy the next poor developer that has to work on your satan-spawned code ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
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.
|
|
|
|