473,811 Members | 3,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why Visual Studio can not optimize the initialization code?

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/lib...57(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
1 1337
George2 wrote:
Hello everyone,
Why Visual Studio compiler can not optimize in this case?
Optimization is beyond the C++ language definition. Further, specific tools
are not discussed here. You should ask in a newsgroup about Visual Studio.
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/lib...57(vs.80).aspx)
This web page is severely broken. It doesn't work in my browser, and the W3
validator reports 63 errors.

Dec 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1525
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 without problems. I have 2 questions : 1. When I launch the Quickstarts, I only see : -------------------------------------------------------------------------------- Microsoft .NET Framework SDK QuickStart Tutorials
1
5563
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 the runtime system during the execution of an image. The profiler receives notifications each time a function is entered or exited, as well as when other events occur that are of interest to the
18
9159
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 page "How to: Connect to Data in an Access Database"
3
1375
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. We've noticed that Visual Studio is terribly inefficient about a lot of things, and my testing with 2005 seems to indicate those problems may actually be worse there. On average, it can take 3 to 5 minutes to simply open the solution while...
4
1182
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? (sample 2, http://msdn2.microsoft.com/en-us/library/ms364057(vs.80).aspx) #include <stdio.h> class A {
4
376
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? http://msdn2.microsoft.com/en-us/library/ms364057(vs.80).aspx
4
11053
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 6.0. Should I allocate memory for this array to avoid the error? If the answer is "Yes", would you please be kind enough to tell me how?
2
2324
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 future. also what is the file Clock.vshost.exe; my application is Clock.exe. Z.K. 'Clock.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\Super_Wizard\My Documents\Visual Studio
2
1164
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#, J#, basically whatever you primarily worked with. I selected C#. It did give you an option to utilise all of the projects, but I silly neglected that. Now, when I go to create a new project I'm only able to create C# projects. The problem is that...
0
9730
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.