Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/08/04 13:08
Read: times


 
Msg Score: -1
 -1 Answer is Wrong
#72045 - RE: Weekend Puzzle
Responding to: ???'s previous message
"I am somewhat surprised that after about 24 hours there has been only one poke at this small program."


Because the code is pure nonsense.

On C all numbers not equal zero are true.
So it is not determined, which values are returned by:
a < b;
and by:
!z

So looking at:

z = a > b;

b = (z * a + !z * b) - (z * b + !z * a);

there are two cases:

1. a <= b:

z = 0

then:

b = xb - ya;

where x = !0 and y = !0 and unknown if x, y == 1 or 2 or 0xFF or what.

2. a > b
then
z != 0 (again it can be 1, 2, 0xFF or what)

and then:
b = za - zb;

which was equal meaningless.


So only what I can say, its a good example of writing very bad code.


ATTENTION:

Never handle logical expressions in arithmetic expressions !!!

The only right usage of logical expressions was in conditional expressions.


So if you want to do the following, why not write it down ?

b = (a > b) ? (a - b) : (b - a);


Peter

List of 35 messages in thread
TopicAuthorDate
Weekend Puzzle            01/01/70 00:00      
   RE: Weekend Puzzle            01/01/70 00:00      
   RE: Weekend Puzzle            01/01/70 00:00      
      RE: Weekend Puzzle            01/01/70 00:00      
      RE: Weekend Puzzle            01/01/70 00:00      
         RE: Weekend Puzzle            01/01/70 00:00      
         RE: Weekend Puzzle            01/01/70 00:00      
            RE: Weekend Puzzle            01/01/70 00:00      
               RE: Weekend Puzzle            01/01/70 00:00      
   RE: Weekend Puzzle            01/01/70 00:00      
      RE: Weekend Puzzle            01/01/70 00:00      
         RE: Weekend Puzzle            01/01/70 00:00      
            RE: Weekend Puzzle            01/01/70 00:00      
               RE: Weekend Puzzle            01/01/70 00:00      
            RE: Weekend Puzzle            01/01/70 00:00      
               RE: Weekend Puzzle            01/01/70 00:00      
            RE: Weekend Puzzle            01/01/70 00:00      
               RE: Weekend Puzzle            01/01/70 00:00      
                  RE: Weekend Puzzle            01/01/70 00:00      
                     RE: Weekend Puzzle            01/01/70 00:00      
                  RE: Weekend Puzzle            01/01/70 00:00      
                     RE: Weekend Puzzle            01/01/70 00:00      
   Understanding logic expressions !!!            01/01/70 00:00      
      RE: Understanding logic expressions !!!            01/01/70 00:00      
   RE: Weekend Puzzle            01/01/70 00:00      
      RE: Weekend Puzzle            01/01/70 00:00      
         RE: Weekend Puzzle            01/01/70 00:00      
   RE: Weekend Puzzle            01/01/70 00:00      
   My Conclusion            01/01/70 00:00      
      RE: My Conclusion            01/01/70 00:00      
   Whats the trick, Michael ?            01/01/70 00:00      
      RE: Whats the trick, Michael ?            01/01/70 00:00      
         RE: Whats the trick, Michael ?            01/01/70 00:00      
            RE: Whats the trick, Michael ?            01/01/70 00:00      
               RE: Whats the trick, Michael ?            01/01/70 00:00      

Back to Subject List