See below, marked with ***

-----Original Message-----
From: Richard Hartman [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 28, 2000 10:40 AM
To: Palm Developer Forum
Subject: Re: Another Debug-ROM catch

[ Snip ]

No ... the constructor is called if an instance of the object
is created.  Seems to me that, although somebody before
mentioned that a "goal" of C++ is that user-created objects
behave like primitive types, well ... they don't.  Primitives don't
have constructors.

*** Yes, they do, it is the initialization code for the RTL
Constructors were originally conceived because it was
recognized that complex types could require initialization.
See the original "C with Classes" white papers for more
info. ***

Constructors are code that runs if the object is declared,
not only if it is referenced.

The linker ought to be aware of this behavior and treat
the constructor of a global object as "included" -- and
then anything -it- references would likewise be included.

[ Snip ]

*** Why? consider the following:

float myfloat;

If I *use* myfloat then floating point support better
be linked into my app.  But, if I switch to an integer
implementation and just leave myfloat declared by
mistake, then it seems reasonable for the optimizer
to determine myfloat is unused and remove it.  And, since
it is the only 'float' in my app, remove the floating
point libs as well.

This is, in fact, what happens with a lot of
compilers/optimizers.  I like to see a warning, but I
don't have a problem with the behavior.  It also does
not generally create a problem with classes, unless
the constructor is being used for something other than
basic type construction.  I won't rehash all
the reasons cited by various people on why it is a 
bad idea to rely on global constructors for system
initialization.  I'll just leave it at fooling
optimizers is just one of the pitfalls. ***

Regards,
-jjf


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to