Re: Controlling initialization order
Re: Controlling initialization order
- Subject: Re: Controlling initialization order
- From: "b.bum" <email@hidden>
- Date: Tue, 25 May 2004 22:34:21 -0700
On May 25, 2004, at 6:30 PM, David Catmull wrote:
> On May 25, 2004, at 11:05 AM, b.bum wrote:
>> The initialization order of C++ objects is unspecified across
>> "translation units" (effective oversimplification: across source
>> files). That CodeWarrior (or other IDE/compiler/linkers) guaranteed
>> the order based upon link order is a feature that isn't within the
>> specification.
>
> I guess I've been living a sheltered life :) I settled for
> restructuring my code.
It seems that many C++ programmers have been living such a life. The
reality is that the initialization order is quite thoroughly
predictable given a controlled set of platform, linker, and compiler.
The problem is that the order is merely coincidence on that
predictability; it is not defined to remain constant as any of the
generally constant variables change over time.
I have encountered many a codebase that worked just fine for years at a
time, only to break horrendously the first time it was used in an
"alien" environment or fashion. It has cost many an hour of debugging
only to find that someone somewhere had forgotten that Class A really
needed to be initialized before Class B. And, of course, the absolute
most funnest part of debugging the problem was often that the debugger
would cause the initialization order to change! (all sarcasm intended)
b.bum
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.