ÇÔ¼ö È£Ãâ º¸¿©ÁÖ±â
If you don't have Borland C++, this can be tricky. But you can fool the compiler to get the
results you need.
Viewing function results
When debugging in C++Builder, you sometimes need to view a
function result before you use this result in the next operation.
You can do so if you use the standalone Turbo Debugger, but if you
don't have Borland C++, you're out of luck. Perhaps the simplest
approach is as follows:
class TAny{
TAny any;
int a = 0; //dummy var to trap the function's result
a = any.MyFunc(1);
a = any.MyFunc(3);
a = any.MyFunc(5);
a = any.MyFunc(7);
a = any.MyFunc(9);
But for an unknown reason, regardless or whether you've checked
FULL DEBUG in the C++Builder IDE's options, the Watch, Inspect,
and Evaluate windows will show the value of the variable a after
the first assignment (in the example, a=any.MyFunc(1);) and will
stick with this value while you press [F7] or [F8] to debug the
other assignments to a. It seems that C++Builder's FULL DEBUG
isn't the same as BC++ 5.0's NO OPTIMIZATIONS: The C++ Builder
compiler sees the variable a as usable only to receive a function
call result (and no other way) and doesn't update it until the
last assignment terminates (in this example, MyFunc(9);).
Fortunately, the language itself has constructions you can use to
fool the compiler: Simply declare the dummy a as
As you probably know, "volatile" prevents the compiler from
assuming it can optimize the use of a variable, and indicates that
the variable can be modified by external events (such as an
interrupt, another thread, and so on). This way, you'll get the
current and last value of a each time you press [F8] and you won't
blame MyFunc, thinking it's returning odd values.
by Claudio Valderrama C., cvalde@dcsc.utfsm.cl
|