# Logic problem

int k;
int m;
TRACE("%d ",!(iNewPlace>=(sLine.length()-1)));      //outputs 1

TRACE("%d ",iNewPlace);      //outputs 0
TRACE("%d ",sLine.length()-1);      //outputs -1

TRACE("%d ",((iNewPlace>=(sLine.length()-1))));      //outputs 0

TRACE("%d ",((m=iNewPlace)>=(k=(sLine.length()-1))));      //outputs 1

TRACE("%d ",0>=-1);      //outputs 1

k=iNewPlace;
m=sLine.length()-1;
TRACE("%d ",k>=m);      //outputs 1

Why is TRACE("%d ",((iNewPlace>=(sLine.length()-1))));      outputting false?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
iNewPlace and sLine.length() are unsigned. 0 - 1 is 0xffffffff which is -1 in two's compliment (signed int) but is a really big number as an unsigned int.

When the values are converted to integers (%d conversion or assignement to a signed int) you get signed comparison. Try comparing iNewPlace with m and I'll bet you get a signed/unsigned comparison warning from the compiler.

Hope this helps,
-bcl
0

Experts Exchange Solution brought to you by