473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

why Visual Studio can not optimize the initialization code?

200 100+
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)

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. class A {
  3.   public:
  4.     A() {printf ("A: I am in constructor\n");i = 1;}
  5.     ~A() { printf ("A: I am in destructor\n"); i = 0;}
  6.     A(const A& a) {printf ("A: I am in copy constructor\n"); i = a.i;}
  7.     int i, x, w;
  8. };
  9.  class B {
  10.   public:
  11.     A a;
  12.     B()  { printf ("B: I am in constructor\n");}
  13.     ~B() { printf ("B: I am in destructor\n");}
  14.     B(const B& b) { printf ("B: I am in copy constructor\n");}
  15. };
  16. A MyMethod()
  17. {
  18.     B* b = new B();
  19.     A a = b->a;
  20.     delete b;
  21.     return (a);
  22. }
  23. int main()
  24. {
  25.     A a;
  26.     a = MyMethod();
  27. }
  28.  

thanks in advance,
George
Dec 19 '07 #1
4 1163
weaknessforcats
9,208 Expert Mod 8TB
Optimization is an advanced topic. You need no be concerned with this until after your C++ program has been coded and debugged. And maybe not even then.

I have been using C++ for 17 years and have not yet needed to optimize. My applications just didn't warrant it.

I would post this question again when you have about 5 yrs C++ experience.
Dec 19 '07 #2
George2
200 100+
Hi weaknessforcats,


I have programmed with C++ for more than 5 years, including the time in school. Any ideas for the question. :-)

Optimization is an advanced topic. You need no be concerned with this until after your C++ program has been coded and debugged. And maybe not even then.

I have been using C++ for 17 years and have not yet needed to optimize. My applications just didn't warrant it.

I would post this question again when you have about 5 yrs C++ experience.

regards,
George
Dec 20 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
In that case, start here: http://msdn2.microsoft.com/en-us/lib...e8(VS.71).aspx.
Dec 20 '07 #4
George2
200 100+
Thanks for your advice, weaknessforcats!


In that case, start here: http://msdn2.microsoft.com/en-us/lib...e8(VS.71).aspx.

regards,
George
Dec 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Noulouk | last post by:
Hi, I build an add-in for Visual Studio 2005. I use the wizzard, I fixed the bug with envdte reference and build my project immediately after the wizzard. All seems to work, the add-in is shown...
1
by: jmd | last post by:
Hello. I have downloaded and installed Visual Studio 2005 February CTP -- Professional Edition (English) from msdn. All works fine (with a few bugs) except the Quickstarts. The Quickstarts install...
1
by: Chris Morse | last post by:
Does anyone know how to profile a VB.NET application? In the VS.NET 2003 docs, I found this: (BEGIN DOC COPY) "A code profiler is a software tool, implemented as a DLL, which is called by...
18
by: surfrat_ | last post by:
Hi, I am having the following problems in getting Microsoft Visual Studio 2005 Professional to link to an Access .mdb database. Please help me to sort this out. Problem 1: The Microsoft...
3
by: karlag92 | last post by:
We have a very large C# winforms client application that is constructed as a single solution currently with 75 projects. We're currently using VS 2003 but will upgrade to 2005 some time next year....
1
by: George2 | last post by:
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? ...
4
by: George2 | last post by:
Hello everyone, Why visual studio does not optimize constructor in this case? I do not understand what the MSDN mentioned, if use different named object, compiler can not optimize. Why? ...
4
by: maria | last post by:
I have an array, string data, which produces the error "Too many initializers". Each one of the 248 rows has 5 items with a maximum total length of 173 characters. I am using Visual Studio...
2
by: Z.K. | last post by:
I was wondering if someone could tell me why I get this message and how to prevent it. If I hit continue, it runs fine, but want to know what I am doing wrong so I won't get this error in the...
2
Markus
by: Markus | last post by:
I recently installed Visual Studio 2008 Professional. On the initial install it gave me a list of options, something to do with optimizing Visual Studio. It gave you the option to optimize it for C#,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.