Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Borland c Builder 6 Bug?

Hi,

Is this a bug in Borland?? Or I am missing something?

void
TemplateTest::Run()
{
uint16 value = 0;

Log() << "Enter in Run, value = 0x" << hex << value << endlog;
F1(value);
Log() << "Exit in Run, value = 0x" << hex << value << endlog;
}
void
TemplateTest::F1(short int &value)
{
Log() << "Enter value in F1, value = 0x" << hex << value << endlog;
F2(value);
Log() << "Exit value in F1, value = 0x" << hex << value << endlog;

}
void
TemplateTest::F2(short int &value)
{
Log() << "Enter value in F2, value = 0x" << hex << value << endlog;
value = 1;
Log() << "Exit value in F2, value = 0x" << hex << value << endlog;
}
//-----------------------
--

RESULT :

TemplateTest starts at: Thu 18/05/2006 07:05:36.
===========================================================================

Enter in Run, value = 0x0
Enter value in F1, value = 0x0
Enter value in F2, value = 0x0
Exit value in F2, value = 0x1
Exit value in F1, value = 0x1
Exit in Run, value = 0x0

Thanks
Yair.
[1317 byte] By [yklecki] at [2007-11-11 8:43:34]
# 1 Re: Borland c Builder 6 Bug?
What is the output you expect and what is the difference between what you expect and the results? In short, where exactly is the bug, if any?
Danny at 2007-11-11 21:01:04 >
# 2 Re: Borland c Builder 6 Bug?
Shouldn't the last line of the output Exit in Run, value = 0x0 be equal to 0x1?
since the value was changed to value = 1 in F2 ?

Yair
yklecki at 2007-11-11 21:02:04 >
# 3 Re: Borland c Builder 6 Bug?
Yes and no. Your value isn't the same in all functions because it's being passed by reference with two incompatible types: unit16, which is unsigned short, and the parameter list expects short. A decent compiler should either refuse to compile this code or at least issue a warning because the compiler has to generate a spurious temp short int variable, which is the actual variable being modified in F2, not the real value declares inside run. In simpler words, your code works as if you passes the variable by value, and attempted to change it inside a function. That function only modifies a copy, not the extern varaible. So, yes it's a bug, but the bugs isn't the different values yoru get but rather, the fact that this code compiles!
Danny at 2007-11-11 21:03:07 >
# 4 Re: Borland c Builder 6 Bug?
Fantastic, Thank you Danny.
I guess you have to be very carefully with the types.

Have a nice weekend.
Yair.
yklecki at 2007-11-11 21:04:13 >