Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: global static variable initialization is not working properly




On Dec 22, 2005, at 9:17 AM, Amol Gajewar wrote:


I am facing one strange problem, in which i am not able to get static object initialized completely or properly before its use, and hence it is giving unexpected results.

Is there any compile time option to force such initialization?
Or is there any other issue which creates such problems?

Initialize the object inside a function. Then it will always be initialized before it's used. The order in which global static objects are initialized isn't reliable, but objects in a function are always initialized before the function is called.


Object& getObject() {
  static Object object;
  return object;
}

  -- Steve

--
-- EMail: email@hidden Phone: (301) 975-5423 --
-- WWW: http://math.nist.gov/mcsd/Staff/SLanger/ Fax: (301) 990-4127 --
-- Mail: NIST; 100 Bureau Drive -- Stop 8910; Gaithersburg, Md 20899-8910 --


-- "I don't think this will work. That's why it's science." --
-- Naomi Langer, 17 Feb 2003 --



_______________________________________________ Do not post admin requests to the list. They will be ignored. Unix-porting mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/unix-porting/email@hidden

This email sent to email@hidden
References: 
 >global static variable initialization is not working properly (From: "Amol Gajewar" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.