»ç¿ëÇϱâ Àü¿¡ ÇÔ¼ö °á°ú°ª º¸¿©ÁÖ±â
If you don't have Borland C++, you can run into trouble trying to view a function result before
using it in the next operation. Click to find out the trick for doing so.
When debugging in C++Builder, sometimes you need to view a
function result before you use that result in the next operation.
If you use the standalone Turbo Debugger, you can do so. But if
you don't have Borland C++, you're out of luck. Perhaps the
simplest approach is as follows:
class TAny{
...
public:
int MyFunc(int param);
};
...
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 of whether you've checked
FULL DEBUG in the C++Builder IDE's options -- the Watch, Inspect,
and Evaluate windows will show the value of "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 Borland
C++ 5.0's NO OPTIMIZATIONS: The C++Builder compiler sees that the
variable "a" is used only to receive a function call result (and
isn't used any other way) and doesn't update it until the last
assignment terminates (in this example, MyFunc(9);). This behavior
is strange because Borland uses the same back-end technology for
both C++ 5.0 and C++Builder 1.0. Perhaps we need more advanced
options in C++Builder. The problem is that we have to set them
manually in the project_name.MAK file.
But if you're thinking about returning the product to Borland,
think again -- the language itself has constructions to fake out
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 Cort , cvalde@dcsc.utfsm.cl |