What happens before main()?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony

    #1

    What happens before main()?

    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



  • Noah Roberts

    #2
    Re: What happens before main()?


    Tony wrote:
    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.

    Comment

    • Victor Bazarov

      #3
      Re: What happens before main()?

      Tony wrote:
      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
      --
      Please remove capital 'A's when replying by e-mail
      I do not respond to top-posted replies, please don't ask


      Comment

      • Pete Becker

        #4
        Re: What happens before main()?

        Noah Roberts wrote:
        Tony wrote:
        >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.
        >
        Implementation-specific, but not implementation-defined. The latter is a
        technical term in the C++ standard. It requires that the implementation
        document its behavior.

        --

        -- Pete
        Roundhouse Consulting, Ltd. (www.versatilecoding.com)
        Author of "The Standard C++ Library Extensions: a Tutorial and
        Reference." (www.petebecker.com/tr1book)

        Comment

        • Noah Roberts

          #5
          Re: What happens before main()?


          Victor Bazarov wrote:
          Tony wrote:
          What happens before main()?
          >
          Construction of static objects defined at the namespace
          level happens.
          What about static objects at the class level? Is that different?

          Comment

          • Tony

            #6
            Re: What happens before main()?


            "Victor Bazarov" <v.Abazarov@com Acast.netwrote in message
            news:FIKdncXpib c8EerYnZ2dnUVZ_ rWdnZ2d@comcast .com...
            Tony wrote:
            >What happens before main()?
            >
            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


            Comment

            • Gavin Deane

              #7
              Re: What happens before main()?


              Noah Roberts wrote:
              Victor Bazarov wrote:
              Tony wrote:
              What happens before main()?
              Construction of static objects defined at the namespace
              level happens.
              >
              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

              Comment

              Working...