Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Logic problem

Posted on 2003-12-07
2
Medium Priority
?
211 Views
Last Modified: 2012-05-04
      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?
0
Comment
Question by:Particleness
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
bcladd earned 500 total points
ID: 9892317
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
 

Author Comment

by:Particleness
ID: 9892338
sLine.lenth() was unsigned, but iNewPlace was signed. Nevertheless you  helped me out.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question