Jump to content
Sign in to follow this  
SvendW

Odd Conditional Array Maths

Recommended Posts

Hej,

 

using BoostC 1.6,

consider the following code:

 

 

int check=2000;

 

int CheckPassedRight(short *piar)

{

int ret;

short Elap;

short Intv;

 

Elap = check - piar[0];

Intv = piar[1];

if ( Elap > Intv )

{

ret = 1;

}

else

{

ret = 0;

}

return ret;

}

 

int CheckPassedWrong(short *piar)

{

int ret;

short Elap;

 

Elap = check - piar[0];

if ( Elap > piar[1] )

{

ret = 1;

}

else

{

ret = 0;

}

return ret;

}

 

void main()

{

short iar[2];

int res;

 

iar[0] = 2010;

iar[1] = 75;

 

while (1)

{

res = CheckPassedRight(iar);

res = CheckPassedWrong(iar);

}

}

 

Both calls: CheckPassedRight) and ...Wrong should give the same result: 0, but CheckPassedWrong ALWAYS returns 1.

 

The only difference is:

 

"Wrong" uses:

if ( Elap > piar[1] )

 

 

"Right" uses:

Intv = piar[1];

if ( Elap > Intv )

 

and consumes more memory and time!

 

PS: I realy like BoostC!

 

 

Is this me or the compiler that is wrong?

 

Regards

SvendW

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...