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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/07/06 06:53
Modified:
  03/07/06 08:21

Read: times


 
#111475 - excellent idea
Responding to: ???'s previous message
I know people who seem to delight in using all the C tricks and produce code which is not clear even to them.The thing which does cause the most confusion and which few books actualy offer a clear explaination of is the if(a=b) assignment and yet its often seen in code is always going to throw anyone reading it.
The confusion arrises because there are two types of compares you can do with if, the normal one is if(a==b)... which compares a to b and returns true if they are equal and the conditional code after the if is executed, if(a=b) assigns b to a and if b is not 0 it returns true and the condition code after the if is executed.this is a common mistake for beginners to type if (a=b) when they really want a compare not an assignment,one way to make sure that the mistake is spotted at compile time is to use the inverted compare i.e. if(2==a)... which will produce a compiler error if you mistakenly type if(2=a) mind you people who remember to use the inverted compare will probably remember to type == rather than = anyway.
The statement [(rpos+rcnt++) % RBUFLEN] calculates (rpos+rcnt) modulo RBUFLEN and then increments rcnt.
You cannot use if(a=b) in C++ unless a and b are both boolean types.

List of 20 messages in thread
TopicAuthorDate
interrupt driven serial: RFC            01/01/70 00:00      
   It must be perfect!            01/01/70 00:00      
      I don't believe            01/01/70 00:00      
         Validation            01/01/70 00:00      
            well ... I've looked at it ...            01/01/70 00:00      
               request for comment on comment            01/01/70 00:00      
                  let's take this a little at a time ...            01/01/70 00:00      
            OK then give yours            01/01/70 00:00      
   Intel Original            01/01/70 00:00      
      on byte buffer            01/01/70 00:00      
   c version            01/01/70 00:00      
      Coloring            01/01/70 00:00      
         html syntax colouring            01/01/70 00:00      
      to C or not to C            01/01/70 00:00      
         yeah but thats the point            01/01/70 00:00      
            How true for "real C"            01/01/70 00:00      
               excellent idea            01/01/70 00:00      
      asm, in the same style            01/01/70 00:00      
   This may not work well ...            01/01/70 00:00      
      How?            01/01/70 00:00      

Back to Subject List