|
-
November 13th, 2009, 09:49 PM
#7
Re: problem with static initilization part two.
 Originally Posted by kempofighter
Yeah, I'd need to see a more complete example that demonstrates the problem. I've never seen that kind of a technique before. The reason for that is as you have already stated. You don't want to make your design too dependent on the order of header inclusions and static variable initialization. You should be able to construct your objects and initialize your variables in any order without worrying about the language rules or differences in compiler implementations. Some compiler writers occasionally get things wrong. Compilers aren't perfect anyway. You need to base your design on the things that you can control and easily explain to another colleague.
Well, the point is to do it in a way order won't matter, that won't require any overhead, and doesn't require making every single variable use a lock and a guard variable.
Turns out there is no way to stop it from initializing it, no matter what. But, what you can do is have its definition initialize it to itself. Then you can use the anon namespace trick to initialize it at definition time without worry.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|