• 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
Re: C++ Constructors on global vars not being run ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ Constructors on global vars not being run ?


  • Subject: Re: C++ Constructors on global vars not being run ?
  • From: Tommy Nordgren <email@hidden>
  • Date: Mon, 24 Sep 2007 14:29:52 +0200


On 24 sep 2007, at 07.06, Peter Mulholland wrote:

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

Are you sure you have typed the constructor name correctly, in your real code?
Enable all warnings and compile again. If you have mistyped a constructor name,
you will get a warning that implicit return type of int is not allowed by the current c++ standard.
----------------------------------
Skinheads are so tired of immigration, that they are going to move to a country that don't accept immigrants!
Tommy Nordgren
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>
References: 
 >C++ Constructors on global vars not being run ? (From: Peter Mulholland <email@hidden>)

  • Prev by Date: Re: C++ Constructors on global vars not being run ?
  • Next by Date: Re: C++ Constructors on global vars not being run ?
  • Previous by thread: Re: Re[2]: C++ Constructors on global vars not being run ?
  • Next by thread: Re: C++ Constructors on global vars not being run ?
  • Index(es):
    • Date
    • Thread