On Feb 9, 2009, at 1:11 AM, Steve Checkoway wrote:
On Feb 7, 2009, at 1:43 AM, Erg Consultant wrote:
I have a simple C routine which looks roughly like this:
I'd like to know why this is happening as a routine returning true even when I set the return value to false is not the way code nor a compiler should behave.
Have you tried changing it to
Boolean IsOnline( char *host, Boolean checkConnection )
{
Boolean result = false;
return result;
}
and checking if it still returns true? While compiler bugs are certainly possible, it seems pretty unlikely. Note that in addition to project and target settings, individual files can have compiler flags. It'd be worth looking at the actual build commands to ensure that no optimization flags are being passed to the compiler.
the statement
return result;
will always set the target variable outside the function - no matter how you corrupted the stack with invalid statements within the function, and no matter of the alignment of the target variable. At least in debug mode, where commands are not reordered.
I can imagine, that a different declaration of Boolean in the two translation units may cause this behavior. I would check also, if Boolean conflicts with _BOOL and bool respectively.
One other reason it might be, is a possible unnoticed bug (stack will be corrupted from commands within the function), a different alignment and a different assembly on machine level in the PCC architecture - so that the bug becomes apparent only there.
Hint:
Look at the "char* host" parameter: it's content may be changed. The compiler has no means to check for xcvalid bounds. Better you use
const char* host
I bet it is 99.9999% a bug in the code. ;)