P. 1
Programing - Learn Visual C++ 6

Programing - Learn Visual C++ 6

|Views: 129|Likes:
Published by HitMAN010

More info:

Published by: HitMAN010 on Feb 20, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less






Most developers are familiar with the cycle of debugging work. You build your project,
you run it, and something unusual happens. You debug for a while to understand why.
You find the bad code, change it, rebuild, rerun, and either find another bug or
convince yourself that the application works. Sometimes you think you've fixed it, but
you haven't. As your project grows, these rebuilds can take a very long time, and they
break the rhythm of your work. It can also take a significant amount of time to run the
application to the trouble spot each time. It's very boring to enter the same information
every time on a dialog box, for example, trying to set up an error condition.

In version 6.0 of Visual C++, in many cases you can keep right on debugging after making
a code change - without rebuilding and without rerunning. This feature is called Edit
and Continue and is sure to be a major time-saver.

To use Edit and Continue, you should start by confirming that it's enabled both for the
product as a whole and for this specific project. First, choose Tools, Options and click
the Debug tab. Make sure that Debug commands Invoke Edit and Continue is selected, as
in Figure D.8. Second, choose Project, Settings and click the C/C++ tab. In the left pane,
make sure you are editing your Debug settings. Ensure that the Debug Info drop-down
box contains Program Database for Edit and Continue. If not, drop the box down, select
this option, as in Figure D.9 (it's last on the list), and then rebuild the project after
exiting the Project Settings dialog. Always check the project settings when you start a
new project, to confirm that Edit and Continue is enabled.

FIG. D.8 Enable Edit And Continue on the Debug tab of the Options dialog.

FIG. D.9 Your project must generate Edit and Continue information.

Now, debug as you always did, but don't automatically click Build after making a code
change: Try to step to the next line. If it's not possible to continue without a build, you
will receive a line of output in the Build tab of the Output window telling you so and
the familiar One or More Files Are out of Date message box offering you a chance to
rebuild your project. If it's possible to continue, you will have saved a tremendous
amount of time.

Most simple code changes, such as changing the condition in an if or for statement or

changing the value to which you set a variable, should work immediately. More complex
changes will require a rebuild. For example, you must rebuild after any one of these

q Any change to a header file, including changing code in an inline function

q Changing a C++ class definition

q Changing a function prototype

q Changing the code in a global (nonmember) function or a static member function

Try it yourself: Imagine that you can't remember why the string originally displayed by
ShowString is black, and you'd like it to be red. You suspect that the OnNewDocument()
function is setting it, so you expand CShowStringDoc in the ClassView and double-click
OnNewDocument(). Then you place a breakpoint (F9) on this line:

string = "Hello, world!";

Click Go (F5), or choose Build, Start Debug, Go; ShowString will run, create a new
document, and stop at your breakpoint. Change the next line of code to read

color = 1; //red

Click Go again and wait. Watch your output window and you will see that
showstringdoc.cpp is recompiling. After a short wait, the familiar Hello, world! will
appear - in red. Your changes went into effect immediately.

When you finish your debugging session, it's a good idea to do a build because the
changes used by Edit and Continue may be in memory only and not written out to your
executable file.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->