• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
C++ Constructors on global vars not being run ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ Constructors on global vars not being run ?


  • Subject: C++ Constructors on global vars not being run ?
  • From: Peter Mulholland <email@hidden>
  • Date: Mon, 24 Sep 2007 06:06:53 +0100

Hello xcode-users,

To simplify the problem a bit, suppose I have:

class something
{
      public:
      something()
      {
                 printf("In constructor for something()\n");
                 somevar = 123;
      }

      int somevar;
} atest;

int main(int argc, char *argv[])
{
    printf("atest.somevar is %d\n", atest.somevar);
    return 0;
}


When I compile code similar to this on gcc, and run it, the
constructor isn't being called before main(), even though it should
be.

What's going on? I looked at settings for ld but couldn't find
anything that handled ctors.

--

Best regards,
 Peter                          mailto:email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: C++ Constructors on global vars not being run ?
      • From: Tommy Nordgren <email@hidden>
    • Re: C++ Constructors on global vars not being run ?
      • From: Peter Mulholland <email@hidden>
  • Prev by Date: Re: Weird error situation
  • Next by Date: Re: Weird error situation
  • Previous by thread: Oops, re: above
  • Next by thread: Re: C++ Constructors on global vars not being run ?
  • Index(es):
    • Date
    • Thread