What happens before main()?

T

Tony

What happens before main()?

Perhaps someone can explain it succintly and perhaps
someone has a link where it is described? crt0.lib or
something like that comes to mind (surely I have the
source code to that given that I have a number of
compilers (some very old) but I'd rather get some
rough idea first of what's happening there). Is it just
setting up an environment in which the C++ library
will work? What happens from the time a program
is started (typing the name on the command line and
pressing enter, for example) until it starts initializing
application program objects and then ending up at main()?

Tony
 
N

Noah Roberts

Tony said:
What happens before main()?

Perhaps someone can explain it succintly and perhaps
someone has a link where it is described? crt0.lib or
something like that comes to mind (surely I have the
source code to that given that I have a number of
compilers (some very old) but I'd rather get some
rough idea first of what's happening there). Is it just
setting up an environment in which the C++ library
will work? What happens from the time a program
is started (typing the name on the command line and
pressing enter, for example) until it starts initializing
application program objects and then ending up at main()?

It's implementation defined.
 
V

Victor Bazarov

Tony said:
What happens before main()?

Construction of static objects defined at the namespace
level happens. Everything else is implementation-defined.
Perhaps someone can explain it succintly and perhaps
someone has a link where it is described?
Perhaps.

crt0.lib or
something like that comes to mind (surely I have the
source code to that given that I have a number of
compilers (some very old) but I'd rather get some
rough idea first of what's happening there). Is it just
setting up an environment in which the C++ library
will work?

Yes. Probably. In your system, that is.
What happens from the time a program
is started (typing the name on the command line and
pressing enter, for example) until it starts initializing
application program objects and then ending up at main()?

That's up to the hosting environment and beyond the scope
of this newsgroup.

V
 
N

Noah Roberts

Victor said:
Construction of static objects defined at the namespace
level happens.

What about static objects at the class level? Is that different?
 
T

Tony

Victor Bazarov said:
Construction of static objects defined at the namespace
level happens. Everything else is implementation-defined.

Sounds like something I may be hacking on at some time.
Maybe all that is necessary is the static initialization and
main() is too specialized for a specific paradigm (the UNIX
filter type of program).

Tony
 
G

Gavin Deane

Noah said:
What about static objects at the class level? Is that different?

The definition of a class's static data member has to appear at
namespace scope so Victor's statement implicitly includes static data
members.

Gavin Deane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top